{"componentChunkName":"component---src-templates-blog-post-js","path":"/javascript/","result":{"data":{"site":{"siteMetadata":{"title":"Recipes Collection","author":"Internet Community"}},"markdownRemark":{"id":"a5568fae-b4e1-5822-af3b-ebacbf89e1f1","html":"<h2 id=\"basics\"><a href=\"#basics\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Basics</h2>\n<h4 id=\"q---what-is-the--not-not-operator-in-javascript\"><a href=\"#q---what-is-the--not-not-operator-in-javascript\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What is the !! (not not) operator in JavaScript?</h4>\n<p>Reference - <a href=\"https://love2dev.com/blog/javascript-not-operator/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://love2dev.com/blog/javascript-not-operator/</a></p>\n<p>This is really a shorthand way to convert any value to a boolean.</p>\n<p>Some say the way to remember this trick is, “bang bang, you’re boolean”.</p>\n<h4 id=\"q---what-are-the-things-that-evaluate-to-falsey-in-javascript\"><a href=\"#q---what-are-the-things-that-evaluate-to-falsey-in-javascript\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What are the things that evaluate to falsey in JavaScript?</h4>\n<p>Reference - <a href=\"https://love2dev.com/blog/javascript-not-operator/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://love2dev.com/blog/javascript-not-operator/</a></p>\n<ul>\n<li>undefined</li>\n<li>null</li>\n<li>NaN</li>\n<li>0</li>\n<li>\"\" (empty string)</li>\n<li>false</li>\n</ul>\n<h4 id=\"q---what-is-amd-commonjs-and-umd\"><a href=\"#q---what-is-amd-commonjs-and-umd\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What is AMD, CommonJS, and UMD?</h4>\n<p>Reference - <a href=\"https://www.davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://www.davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/</a></p>\n<h4 id=\"q---define-primitive-types\"><a href=\"#q---define-primitive-types\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - Define primitive types.</h4>\n<p>A <strong>primitive</strong> (primitive value, primitive data type) is data that is not an object and has no methods.</p>\n<p>All primitives are immutable, i.e., they cannot be altered.</p>\n<h4 id=\"q---what-are-the-primitive-types-in-javascript\"><a href=\"#q---what-are-the-primitive-types-in-javascript\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What are the primitive types in JavaScript?</h4>\n<ol>\n<li>String : <code class=\"language-text\">typeof instance === &quot;string&quot;</code></li>\n<li>Number : <code class=\"language-text\">typeof instance === &quot;number&quot;</code></li>\n<li>Boolean : <code class=\"language-text\">typeof instance === &quot;boolean&quot;</code></li>\n<li>BigInt : <code class=\"language-text\">typeof instance === &quot;bigint&quot;</code></li>\n<li>undefined : <code class=\"language-text\">typeof instance === &quot;undefined&quot;</code></li>\n<li>Symbol : <code class=\"language-text\">typeof instance === &quot;symbol&quot;</code></li>\n</ol>\n<p>Reference - <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures</a></p>\n<h4 id=\"q---what-are-the-non-primitive-types-object-references-in-javascript\"><a href=\"#q---what-are-the-non-primitive-types-object-references-in-javascript\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What are the non-primitive types (Object references) in JavaScript?</h4>\n<ol>\n<li>null : <code class=\"language-text\">typeof instance === &quot;object&quot;</code></li>\n<li>\n<p>Object : <code class=\"language-text\">typeof instance === &quot;object&quot;</code>\nSpecial non data but Structural type for any constructed instance</p>\n<p>new Object, new Array, new Map, new Set, new WeakMap, new WeakSet, new Date and almost everything made with new keyword;</p>\n</li>\n<li>Function: <code class=\"language-text\">typeof instance === &quot;function&quot;</code></li>\n</ol>\n<h4 id=\"q---what-is-a-closure\"><a href=\"#q---what-is-a-closure\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What is a Closure?</h4>\n<p>A <strong>closure</strong> is the combination of a function bundled together (enclosed) with references to its surrounding state (the <strong>lexical environment</strong>). </p>\n<p>In other words, a closure gives you access to an outer function’s scope from an inner function.</p>\n<p>In other words, a closure is nothing but functions with preserved data.</p>\n<p>Reference - <a href=\"https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-closure-b2f0d2152b36\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-closure-b2f0d2152b36</a></p>\n<p>Reference - <a href=\"https://www.youtube.com/watch?v=71AtaJpJHw0&#x26;ab_channel=techsith\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://www.youtube.com/watch?v=71AtaJpJHw0&#x26;ab_channel=techsith</a></p>\n<h4 id=\"q---give-an-example-of-a-closure\"><a href=\"#q---give-an-example-of-a-closure\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - Give an example of a closure.</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">var</span> <span class=\"token function-variable function\">addTo</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">passed</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">var</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\">inner</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> passed <span class=\"token operator\">+</span> inner<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> add<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> addThree <span class=\"token operator\">=</span> <span class=\"token function\">addTo</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\">var</span> addFour <span class=\"token operator\">=</span> <span class=\"token function\">addTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</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\">addThree</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\">// 4</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">addFour</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\">// 5</span></code></pre></div>\n<p>Reference - <a href=\"https://www.youtube.com/watch?v=71AtaJpJHw0&#x26;ab_channel=techsith\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://www.youtube.com/watch?v=71AtaJpJHw0&#x26;ab_channel=techsith</a></p>\n<h2 id=\"advanced\"><a href=\"#advanced\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Advanced</h2>\n<h3 id=\"tree-shaking\"><a href=\"#tree-shaking\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tree Shaking</h3>\n<h4 id=\"q---what-is-tree-shaking\"><a href=\"#q---what-is-tree-shaking\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What is tree shaking?</h4>\n<ul>\n<li>It is the process used to remove dead code.</li>\n<li>The module bundlers (e.g. webpack, rollup) would automatically remove unused modules in the bundle during the build process.</li>\n<li>This only works with <code class=\"language-text\">import</code> and <code class=\"language-text\">export</code>.</li>\n<li>It won’t work with CommonJS <code class=\"language-text\">require</code> syntax.</li>\n</ul>\n<p>References</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking</a></li>\n<li><a href=\"https://medium.com/@netxm/what-is-tree-shaking-de7c6be5cadd\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://medium.com/@netxm/what-is-tree-shaking-de7c6be5cadd</a></li>\n</ul>\n<h4 id=\"q---what-is-the-benefit-of-tree-shaking\"><a href=\"#q---what-is-the-benefit-of-tree-shaking\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Q - What is the benefit of tree shaking?</h4>\n<ul>\n<li>Tree shaking helps to significantly reduce the bundle size thus improving performance.</li>\n</ul>\n<p>References</p>\n<ul>\n<li><a href=\"https://medium.com/@netxm/what-is-tree-shaking-de7c6be5cadd\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://medium.com/@netxm/what-is-tree-shaking-de7c6be5cadd</a></li>\n</ul>","timeToRead":4,"frontmatter":{"title":"JavaScript","date":"November 01, 2019","spoiler":"Following are some notes collected through internet"},"fields":{"slug":"/javascript/","langKey":"en"}}},"pageContext":{"slug":"/javascript/","previous":{"fields":{"slug":"/javascript-tools/","langKey":"en","directoryName":"javascript-tools","maybeAbsoluteLinks":[]},"frontmatter":{"title":"JavaScript Tools"}},"next":{"fields":{"slug":"/REST/","langKey":"en","directoryName":"REST","maybeAbsoluteLinks":[]},"frontmatter":{"title":"REST"}},"translations":[],"translatedLinks":[]}}}