<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dan-Vy Le</title>
    <description>The latest articles on DEV Community by Dan-Vy Le (@danvyle).</description>
    <link>https://dev.to/danvyle</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F184723%2F1222f573-38a0-4b9c-ad15-52139867f2d0.jpg</url>
      <title>DEV Community: Dan-Vy Le</title>
      <link>https://dev.to/danvyle</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danvyle"/>
    <language>en</language>
    <item>
      <title>MJSQ 101: Why not touch global scope?</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 01 Apr 2020 09:29:39 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-why-not-touch-global-scope-2c0p</link>
      <guid>https://dev.to/danvyle/mjsq-101-why-not-touch-global-scope-2c0p</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions answered!:&lt;/p&gt;

&lt;p&gt;Question this week:&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is it, in general, a good idea to leave the global scope of a website as-is and never touch it?
&lt;/h2&gt;

&lt;p&gt;I thought Yangshun's explanation is concise so I'll just leave it here verbatim: &lt;/p&gt;

&lt;p&gt;Every script has access to the global scope, and if everyone uses the global namespace to define their variables, collisions will likely occur. Use the module pattern (IIFEs) to encapsulate your variables within a local namespace.&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quotes from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>MJSQ 101: Function.prototype.bind</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 25 Mar 2020 05:54:08 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-function-prototype-bind-486h</link>
      <guid>https://dev.to/danvyle/mjsq-101-function-prototype-bind-486h</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions answered!:&lt;/p&gt;

&lt;p&gt;Question this week:&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain Function.prototype.bind
&lt;/h2&gt;

&lt;p&gt;Taken word-for-word from MDN:&lt;/p&gt;

&lt;p&gt;The bind() method creates a new function that, when called, has its &lt;code&gt;this&lt;/code&gt; keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;getX&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;unboundGetX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;unboundGetX&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// The function gets invoked at the global scope&lt;/span&gt;
&lt;span class="c1"&gt;// expected output: undefined&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;boundGetX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;unboundGetX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;boundGetX&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// expected output: 42&lt;/span&gt;


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



&lt;p&gt;In their example, the unboundGetX variable cannot call on the module variable's getX function until it has been bound with the Function.prototype.bind method.&lt;/p&gt;

&lt;p&gt;This approach would be good when you're wanting to bind the value of &lt;code&gt;this&lt;/code&gt; to pass into other functions.&lt;/p&gt;

&lt;p&gt;References&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind"&gt;https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quotes from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>MJSQ 101: Feature detection, feature inference, UA string</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 18 Mar 2020 04:24:51 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-feature-detection-feature-inference-ua-string-a2j</link>
      <guid>https://dev.to/danvyle/mjsq-101-feature-detection-feature-inference-ua-string-a2j</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions answered!:&lt;/p&gt;

&lt;p&gt;Question this week:&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the difference between feature detection, feature inference, and using the UA string?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Feature Detection
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Feature detection&lt;/em&gt; is discovering if a browser supports a certain block of code by running tests and running different code depending on if it does or does not. This allows for the browser to always provide a working experience instead of crashing or rendering errors giving a bad user experience.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;geolocation&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;geolocation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getCurrentPosition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// show the location on a map, perhaps using the Google Maps API&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Give the user a choice of static maps instead perhaps&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Modernizr is a great library to handle feature detection.&lt;/p&gt;

&lt;h3&gt;
  
  
  Feature Inference
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Feature inference&lt;/em&gt; is similar to feature detection, but instead uses another function because it assumes it will also exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementsByTagName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;really&lt;/span&gt; &lt;span class="nx"&gt;recommended&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;Feature&lt;/span&gt; &lt;span class="nx"&gt;detection&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;more&lt;/span&gt; &lt;span class="nx"&gt;foolproof&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  UA String
&lt;/h3&gt;

&lt;p&gt;This is a browser-reported string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent. It can be accessed via navigator.userAgent. However, the string is tricky to parse and can be spoofed. For example, Chrome reports both as Chrome and Safari. So to detect Safari you have to check for the Safari string and the absence of the Chrome string. Avoid this method.&lt;/p&gt;

&lt;p&gt;Checking the UA string is an old practice and should not be used anymore. You keep changing the UA checks and never benefit from newly implemented features, e.g.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userAgent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;MSIE 7&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="c1"&gt;//do something&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quotes from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>MJSQ 101: .concat()</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 11 Mar 2020 08:35:19 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-concat-1bj5</link>
      <guid>https://dev.to/danvyle/mjsq-101-concat-1bj5</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions answered!:&lt;/p&gt;

&lt;p&gt;Let's tackle another easy quick algorithm question this week:&lt;/p&gt;

&lt;h2&gt;
  
  
  Make this work:  &lt;code&gt;duplicate([1,2,3,4,5]); // [1,2,3,4,5,1,2,3,4,5]&lt;/code&gt;]
&lt;/h2&gt;

&lt;h4&gt;
  
  
  The solution:
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;duplicate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;duplicate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;

&lt;span class="c1"&gt;//output: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]&lt;/span&gt;

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



&lt;h4&gt;
  
  
  What do we know:
&lt;/h4&gt;

&lt;p&gt;It looks like the input is &lt;code&gt;[1,2,3,4,5]&lt;/code&gt; and the desired output is &lt;code&gt;[1,2,3,4,5,1,2,3,4,5]&lt;/code&gt;.&lt;br&gt;
It also looks like it's calling a function duplicate() to make this work.&lt;br&gt;
We also know of a quick array method that can add one array onto another, it's called concat()&lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;//output: [8, 6, 7, 5, 3, 0, 9]&lt;/span&gt;

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



&lt;h4&gt;
  
  
  Pseudocode:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;So we would need to write the &lt;code&gt;function&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;and call it &lt;code&gt;duplicate(arr)&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;so that it could take an argument, such as an array of &lt;code&gt;[1, 2, 3, 4, 5]&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;and work with the &lt;code&gt;concat()&lt;/code&gt; array method to add the original array to itself. &lt;/li&gt;
&lt;li&gt;We would then return &lt;code&gt;arr.concat(arr)&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;so that when we display the output or `console.log()the function, &lt;/li&gt;
&lt;li&gt;the output will give you the input twice in a new array: &lt;code&gt;[1,2,3,4,5,1,2,3,4,5]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's the solution again in case you are one of those models that can only scroll down.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`js&lt;/p&gt;

&lt;p&gt;function duplicate(arr) {&lt;br&gt;
    return arr.concat(arr)&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;console.log(duplicate([1, 2, 3, 4, 5]))&lt;/p&gt;

&lt;p&gt;//output: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quotes from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>MJSQ 101: FizzBuzz</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Tue, 03 Mar 2020 08:40:05 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-fizzbuzz-45ln</link>
      <guid>https://dev.to/danvyle/mjsq-101-fizzbuzz-45ln</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions answered!:&lt;/p&gt;

&lt;p&gt;Topic covered today:&lt;/p&gt;

&lt;h2&gt;
  
  
  FizzBuzz
&lt;/h2&gt;

&lt;p&gt;It's one of the most common JS questions that you'll see, I've seen it three times now, in an intro to algorithms/whiteboarding, in a practice technical interview and now from Yangshun's front-end questions. It's worth it to take a deeper look.&lt;/p&gt;

&lt;h4&gt;
  
  
  The prompt:
&lt;/h4&gt;

&lt;p&gt;Create a for loop that iterates up to 100 while outputting "fizz" at multiples of 3, "buzz" at multiples of 5 and "fizzbuzz" at multiples of 3 and 5.&lt;/p&gt;

&lt;h4&gt;
  
  
  A solution:
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fizzBuzz&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;FizzBuzz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fizz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Buzz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;fizzBuzz&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Solution broken down:
&lt;/h4&gt;

&lt;p&gt;There are a few things that we know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We need to print the numbers 1-100. &lt;/li&gt;
&lt;li&gt;If the number is divisible by 3, the number will be replaced with "Fizz"&lt;/li&gt;
&lt;li&gt;If the number is divisible by 5, the number will be replaced with "Buzz"&lt;/li&gt;
&lt;li&gt;If the number is divisible by 3 &amp;amp; 5, the number will be replaced with "FizzBuzz"&lt;/li&gt;
&lt;li&gt;We'll go through all of this until we hit 100.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are a few things that would work well for the solution if we know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To print something on screen, we can &lt;code&gt;console.log()&lt;/code&gt; it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator allows for us to combine more than one conditional statement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;The Modulo operator&lt;/em&gt; or &lt;em&gt;&lt;code&gt;%&lt;/code&gt;&lt;/em&gt; in javascript doesn't mean percent (unless it's written out in a string). A &lt;em&gt;modulo operator&lt;/em&gt; does this cool calculation where it tells you what the remainder of a number is once it has been divided by the number on the right side of the operator. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Take for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; 
 &lt;span class="c1"&gt;//output = 0. 30 is perfectly divisible by 5 so its output is 0. &lt;/span&gt;

 &lt;span class="mi"&gt;31&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
 &lt;span class="c1"&gt;//output = 1. 31 divided by 5 is 6 plus some change, in this case it's 1.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Conditional statements &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;else if&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;//do something here if conditional statement is truthy&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;another&lt;/span&gt; &lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="nx"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;//do another thing if statement is truthy&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;//catch all for whatever else is left basically&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;for&lt;/code&gt; loop. A &lt;code&gt;for&lt;/code&gt; loop takes three statements: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Statement 1 is executed (one time) before the execution of the code block. var i is declared before we start the loop.&lt;/p&gt;

&lt;p&gt;Statement 2 defines the condition for executing the code block. The loop will run until i &amp;lt; 100 is no longer true aka when i &amp;gt; 100: STOP.&lt;/p&gt;

&lt;p&gt;Statement 3 is executed (every time) after the code block has been executed. Whatever i is, add 1 to itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here's the solution with a shit ton of comments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fizzBuzz&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="c1"&gt;//we create a function called fizzBuzz() to be called later in the program once we run it&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//this is a for loop to declare i to start at 1, until it is equal to or greater than 100, and once it executes, add i + 1&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//inside the for loop, we need to exercise a conditional. If i is perfectly divisible by 5 &amp;amp;&amp;amp; divisible by 3, where the result of using the modulo operator is equal to 0, let's console.log("FizzBuzz")&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;FizzBuzz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//Or if it's only perfectly divisible by 3, we can say "Fizz"&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fizz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//Or if it's only perfectly divisible by 3, we can say "Buzz"&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Buzz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;//or if it's not divisible by any of those numbers, let's just print whatever i is.&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;fizzBuzz&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;//call the function and the numbers and Fizz and/or Buzzes will come streaming out.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hope that explains how to code the all too common FizzBuzz question!&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quotes from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>MJSQ 101: == vs ===, use strict, event bubbling</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 26 Feb 2020 07:01:53 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-vs-use-strict-event-bubbling-5b1g</link>
      <guid>https://dev.to/danvyle/mjsq-101-vs-use-strict-event-bubbling-5b1g</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions answered!:&lt;/p&gt;

&lt;p&gt;Topics covered today:&lt;/p&gt;

&lt;h3&gt;
  
  
  1) &lt;code&gt;==&lt;/code&gt; vs &lt;code&gt;===&lt;/code&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  2) &lt;code&gt;"use strict"&lt;/code&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  3) event bubbling
&lt;/h3&gt;

&lt;h2&gt;
  
  
  What is the difference between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt; ?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;==&lt;/code&gt;&lt;/strong&gt; is the abstract equality operator&lt;/p&gt;

&lt;p&gt;This operator essentially does type conversions for you, so it will produce a &lt;code&gt;true&lt;/code&gt; result when the content is the same but type is not the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output true&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;===&lt;/code&gt;&lt;/strong&gt; is the strict equality operator&lt;/p&gt;

&lt;p&gt;This operator will only produce a &lt;code&gt;true&lt;/code&gt; result if the content and type are equal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output false&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What is "use strict";? what are the advantages and disadvantages to using it?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;"use strict"&lt;/code&gt; was introduced with ECMASCript version 5. It indicates that the code should be executed in "strict mode". "Strict mode" makes it easier to write "secure" JavaScript. It will produce errors for previously accepted "bad syntax". &lt;/p&gt;

&lt;p&gt;Things not allowed in "strict mode":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not declaring a variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Not declaring an object
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deleting a variable(or object)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deleting a function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Duplicating a parameter
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Octal numeric literals
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;010&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Octal escape characters
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;010&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Writing to a read-only property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Writing to a get-only property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deleting an undeletable property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using the word &lt;code&gt;eval&lt;/code&gt; as a variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using the word &lt;code&gt;arguments&lt;/code&gt; as a variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;with&lt;/code&gt; statement
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)};&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using eval() to create variables in the scope from which it was called
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;var x = 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;alert&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The this keyword in functions behaves differently in strict mode.&lt;/p&gt;

&lt;p&gt;The this keyword refers to the object that called the function.&lt;/p&gt;

&lt;p&gt;If the object is not specified, functions in strict mode will return undefined and functions in normal mode will return the global object (window):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will alert "undefined"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As a newbie, my actual use of &lt;code&gt;'use strict'&lt;/code&gt; is limited, so we can call on  Yangshun's take on its advantages and disadvantages:&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Makes it impossible to accidentally create global variables.&lt;/li&gt;
&lt;li&gt;Makes assignments which would otherwise silently fail to throw an exception.&lt;/li&gt;
&lt;li&gt;Makes attempts to delete undeletable properties throw (where before the attempt would simply have no effect).&lt;/li&gt;
&lt;li&gt;Requires that function parameter names be unique.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;this&lt;/code&gt; is undefined in the global context.&lt;/li&gt;
&lt;li&gt;It catches some common coding bloopers, throwing exceptions.&lt;/li&gt;
&lt;li&gt;It disables features that are confusing or poorly thought out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Many missing features that some developers might be used to.&lt;/li&gt;
&lt;li&gt;No more access to &lt;code&gt;function.caller&lt;/code&gt; and &lt;code&gt;function.arguments&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Concatenation of scripts written in different strict modes might cause issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Describe event bubbling.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Event bubbling&lt;/strong&gt; is what allows event delegation to happen. Event bubbling directs an intended target to keep going up and up until  it gets handled. &lt;/p&gt;

&lt;p&gt;Here's an example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A button is clicked and the event is directed to the button&lt;/li&gt;
&lt;li&gt;If an event handler is set for that object, the event is triggered&lt;/li&gt;
&lt;li&gt;If no event handler is set for that object, the event bubbles up (like a bubble in water) to the objects' parent&lt;/li&gt;
&lt;li&gt;The event bubbles up from parent to parent until it is handled, or until it reaches the document object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quotes from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;br&gt;
&lt;a href="https://www.w3schools.com/jsref/event_bubbles.asp"&gt;https://www.w3schools.com/jsref/event_bubbles.asp&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>MJSQ 101: == vs. ===, Use Strict, Event Bubbling, </title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 26 Feb 2020 06:58:06 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-vs-use-strict-event-bubbling-1ea2</link>
      <guid>https://dev.to/danvyle/mjsq-101-vs-use-strict-event-bubbling-1ea2</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions answered!:&lt;/p&gt;

&lt;p&gt;Topics covered today:&lt;/p&gt;

&lt;h3&gt;
  
  
  1) &lt;code&gt;==&lt;/code&gt; vs &lt;code&gt;===&lt;/code&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  2) &lt;code&gt;"use strict"&lt;/code&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  3) event bubbling
&lt;/h3&gt;

&lt;h2&gt;
  
  
  What is the difference between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt; ?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;==&lt;/code&gt;&lt;/strong&gt; is the abstract equality operator&lt;/p&gt;

&lt;p&gt;This operator essentially does type conversions for you, so it will produce a &lt;code&gt;true&lt;/code&gt; result when the content is the same but type is not the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output true&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;===&lt;/code&gt;&lt;/strong&gt; is the strict equality operator&lt;/p&gt;

&lt;p&gt;This operator will only produce a &lt;code&gt;true&lt;/code&gt; result if the content and type are equal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output false&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//output true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What is "use strict";? what are the advantages and disadvantages to using it?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;"use strict"&lt;/code&gt; was introduced with ECMASCript version 5. It indicates that the code should be executed in "strict mode". "Strict mode" makes it easier to write "secure" JavaScript. It will produce errors for previously accepted "bad syntax". &lt;/p&gt;

&lt;p&gt;Things not allowed in "strict mode":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not declaring a variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Not declaring an object
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deleting a variable(or object)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deleting a function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Duplicating a parameter
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Octal numeric literals
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;010&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Octal escape characters
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;010&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Writing to a read-only property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Writing to a get-only property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deleting an undeletable property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using the word &lt;code&gt;eval&lt;/code&gt; as a variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using the word &lt;code&gt;arguments&lt;/code&gt; as a variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;with&lt;/code&gt; statement
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)};&lt;/span&gt; 
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using eval() to create variables in the scope from which it was called
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;var x = 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;alert&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//  This will cause an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The this keyword in functions behaves differently in strict mode.&lt;/p&gt;

&lt;p&gt;The this keyword refers to the object that called the function.&lt;/p&gt;

&lt;p&gt;If the object is not specified, functions in strict mode will return undefined and functions in normal mode will return the global object (window):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will alert "undefined"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As a newbie, my actual use of &lt;code&gt;'use strict'&lt;/code&gt; is limited, so we can call on  Yangshun's take on its advantages and disadvantages:&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Makes it impossible to accidentally create global variables.&lt;/li&gt;
&lt;li&gt;Makes assignments which would otherwise silently fail to throw an exception.&lt;/li&gt;
&lt;li&gt;Makes attempts to delete undeletable properties throw (where before the attempt would simply have no effect).&lt;/li&gt;
&lt;li&gt;Requires that function parameter names be unique.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;this&lt;/code&gt; is undefined in the global context.&lt;/li&gt;
&lt;li&gt;It catches some common coding bloopers, throwing exceptions.&lt;/li&gt;
&lt;li&gt;It disables features that are confusing or poorly thought out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Many missing features that some developers might be used to.&lt;/li&gt;
&lt;li&gt;No more access to &lt;code&gt;function.caller&lt;/code&gt; and &lt;code&gt;function.arguments&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Concatenation of scripts written in different strict modes might cause issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Describe event bubbling.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Event bubbling&lt;/strong&gt; is what allows event delegation to happen. Event bubbling directs an intended target to keep going up and up until  it gets handled. &lt;/p&gt;

&lt;p&gt;Here's an example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A button is clicked and the event is directed to the button&lt;/li&gt;
&lt;li&gt;If an event handler is set for that object, the event is triggered&lt;/li&gt;
&lt;li&gt;If no event handler is set for that object, the event bubbles up (like a bubble in water) to the objects' parent&lt;/li&gt;
&lt;li&gt;The event bubbles up from parent to parent until it is handled, or until it reaches the document object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quotes from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;br&gt;
&lt;a href="https://www.w3schools.com/jsref/event_bubbles.asp"&gt;https://www.w3schools.com/jsref/event_bubbles.asp&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>MJSQ 101: Ajax</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 19 Feb 2020 03:56:53 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-ajax-i5f</link>
      <guid>https://dev.to/danvyle/mjsq-101-ajax-i5f</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions!:&lt;/p&gt;

&lt;p&gt;We're getting into some AJAX questions today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain Ajax in as much detail as possible.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AJAX&lt;/strong&gt; stands for Asynchronous Javascript And XML. Ajax is not a programming language. Instead it is a combination of technologies including: HTML or XHTML, CSS, JavaScript, DOM, XML, XSLT, and most importantly the *XMLHttpRequest object. This allows for web applications to make quick, incremental changes to the user interface in the background (asynchronously) without having to relaod the entire browser page. &lt;/p&gt;

&lt;p&gt;As a result, your application works much faster and is more responsive to user actions. &lt;/p&gt;

&lt;p&gt;To note: Althought AJAX includes XML, modern convention shows JSON being more frequently used due to it being lighter and native to JavaScript. They are both used for packaging information in the AJAX model.&lt;/p&gt;

&lt;p&gt;*We use XMLHttpRequest (XHR) objects to interact with servers. You can retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without disrupting what the user is doing. XMLHttpRequest is used heavily in AJAX programming.&lt;/p&gt;

&lt;p&gt;Here's a quick diagram and explanation from w3schools of how it works:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pHXiXrb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://www.w3schools.com/js/pic_ajax.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pHXiXrb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://www.w3schools.com/js/pic_ajax.gif" alt="photo-of-ajax-in-action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An event occurs in a web page (the page is loaded, a button is clicked)&lt;/li&gt;
&lt;li&gt;An XMLHttpRequest object is created by JavaScript&lt;/li&gt;
&lt;li&gt;The XMLHttpRequest object sends a request to a web server&lt;/li&gt;
&lt;li&gt;The server processes the request&lt;/li&gt;
&lt;li&gt;The server sends a response back to the web page&lt;/li&gt;
&lt;li&gt;The response is read by JavaScript&lt;/li&gt;
&lt;li&gt;Proper action (like page update) is performed by JavaScript&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What are the advantages and disadvantages of using Ajax?
&lt;/h2&gt;

&lt;p&gt;I'm going to take straight from Yangshun on this one as I think they hit the points well:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better interactivity. New content from the server can be changed dynamically without the need to reload the entire page.&lt;/li&gt;
&lt;li&gt;Reduce connections to the server since scripts and stylesheets only have to be requested once.&lt;/li&gt;
&lt;li&gt;State can be maintained on a page. JavaScript variables and DOM state will persist because the main container page was not reloaded.&lt;/li&gt;
&lt;li&gt;See advantages of an SPA.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic webpages are harder to bookmark.&lt;/li&gt;
&lt;li&gt;Does not work if JavaScript has been disabled in the browser.&lt;/li&gt;
&lt;li&gt;Some webcrawlers do not execute JavaScript and would not see content that has been loaded by JavaScript.&lt;/li&gt;
&lt;li&gt;Webpages using Ajax to fetch data will likely have to combine the fetched remote data with client-side templates to update the DOM. For this to happen, JavaScript will have to be parsed and executed on the browser, and low-end mobile devices might struggle with this.&lt;/li&gt;
&lt;li&gt;See disadvantages of an SPA.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Explain how JSONP works and how it's not really Ajax
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JSONP&lt;/strong&gt; can be seen as a workaround to the cross-origin domain policy and doesn't use the XMLHttpRequest object. &lt;strong&gt;JSONP&lt;/strong&gt; stands for JSON with Padding. JSONP won't use the XMLHttpRequest object. Instead, it uses &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags. This eliminates the issues caused by the cross-origin domain policy. Requesting an external script from another domain doesn't create this problem, hence JSONP. &lt;/p&gt;

&lt;p&gt;JSONP works by making a request to a cross-origin domain via a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag and usually with a callback query parameter, for example: &lt;code&gt;https://example.com?callback=printData&lt;/code&gt;. The server will then wrap the data within a function called &lt;code&gt;printData&lt;/code&gt; and return it to the client.&lt;/p&gt;

&lt;p&gt;An aside: JSONP can be unsafe and has some security implications, so you need to trust the provider of the JSONP data. CORS is the modern recommended approach.&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quote from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX"&gt;https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest"&gt;https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/js/js_ajax_intro.asp"&gt;https://www.w3schools.com/js/js_ajax_intro.asp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/a/2067584/1751946"&gt;https://stackoverflow.com/a/2067584/1751946&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>More JavaScript Questions 101(MJSQ 101): this</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Thu, 13 Feb 2020 01:22:45 +0000</pubDate>
      <link>https://dev.to/danvyle/more-javascript-questions-101-mjsq-101-this-53i4</link>
      <guid>https://dev.to/danvyle/more-javascript-questions-101-mjsq-101-this-53i4</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, I give you more javascript 101 questions!:&lt;/p&gt;

&lt;p&gt;Today's blog will be dedicated to answering how &lt;code&gt;this&lt;/code&gt; works.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; can produce many different results and a lot of it is case dependent. Because you're in the world of JS, a great way to determine what &lt;code&gt;this&lt;/code&gt; is, is to &lt;code&gt;console.log(this)&lt;/code&gt; to check. BUT, if you want to understand the background work that is happening, please read on.&lt;/p&gt;

&lt;p&gt;Arnav Aggarwal has a great blog explaining how &lt;code&gt;this&lt;/code&gt; works. Much of the examples below are taken directly from his blog. &lt;/p&gt;

&lt;p&gt;The highest rule of all is that &lt;code&gt;this&lt;/code&gt; is determined when a function is invoked (it's &lt;strong&gt;call site&lt;/strong&gt;) The remaining rules in order of precedence is showcased below:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. If &lt;code&gt;new&lt;/code&gt; keyword is used when calling a function,  &lt;code&gt;this&lt;/code&gt; is a brand new object.
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;forExample&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;football&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;forExample&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;//output: {}&lt;/span&gt;
&lt;span class="c1"&gt;//output: {value: 'football}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  2. If &lt;code&gt;apply&lt;/code&gt;, &lt;code&gt;call&lt;/code&gt;, or &lt;code&gt;bind&lt;/code&gt; are used to call a function, &lt;code&gt;this&lt;/code&gt; inside the function is the object(in this case, &lt;code&gt;touchdown&lt;/code&gt;) that is passed in as the argument.
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;touchdown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;bindscore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;touchdown&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;bindscore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;     &lt;span class="c1"&gt;// output: -&amp;gt; { value: 6 }&lt;/span&gt;
&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;touchdown&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// output:  { value: 6 }&lt;/span&gt;
&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;touchdown&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// -&amp;gt; output: { value: 6 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  3. If a function is called as a method, &lt;code&gt;this&lt;/code&gt; is the object. When a dot is to the left of the function invoked, &lt;code&gt;this&lt;/code&gt; is the object to the left of the dot.
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;printThis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;printThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="c1"&gt;//output: {value: 5, printThis: function()}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  4. If a function is invoked as a &lt;strong&gt;free function invocation&lt;/strong&gt;, (global), &lt;code&gt;this&lt;/code&gt; is the global object. In a browser, it's the &lt;code&gt;window&lt;/code&gt;.
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// If called in browser:&lt;/span&gt;
&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// output: Window {stop: ƒ, open: ƒ, alert: ƒ, ...}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To note: If multiple scenarios exist, the order of the previous mentioned conditions are important in establishing &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. If the function is an ES2015 arrow function, all rules are thrown out the window. To determine &lt;code&gt;this&lt;/code&gt;, go a line above the arrow function's creation and see what &lt;code&gt;this&lt;/code&gt; is there. It will be the same in the arrow function.
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Chiefs win superbowl.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;createArrowFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrowFn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createArrowFn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;arrowFn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="c1"&gt;// output: { value: 'Chiefs win superbowl.', createArrowFn: ƒ }&lt;/span&gt;

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



&lt;p&gt;Hope this explains &lt;code&gt;this&lt;/code&gt; better for you!&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quote from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;br&gt;
&lt;a href="https://codeburst.io/the-simple-rules-to-this-in-javascript-35d97f31bde3"&gt;https://codeburst.io/the-simple-rules-to-this-in-javascript-35d97f31bde3&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>MJSQ 101: IIFE, anonymous functions, native vs host objects</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 05 Feb 2020 06:55:32 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-iife-anonymous-functions-native-vs-host-objects-4mp7</link>
      <guid>https://dev.to/danvyle/mjsq-101-iife-anonymous-functions-native-vs-host-objects-4mp7</guid>
      <description>&lt;h2&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h2&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, more javascript 101 questions!:&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain why the following doesn't work as an IIFE: &lt;code&gt;function foo(){ }();&lt;/code&gt;. What needs to be changed to properly make it an IIFE?
&lt;/h2&gt;

&lt;p&gt;First you'll need to understand what an IIFE is. An &lt;strong&gt;IIFE&lt;/strong&gt; (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;whoWonSuperBowl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kansas City Chiefs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;whoWonSuperBowl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;

&lt;span class="c1"&gt;//output: "Kansas City Chiefs"&lt;/span&gt;

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



&lt;p&gt;&lt;code&gt;function foo() {} ();&lt;/code&gt; is reading the two as separate: &lt;code&gt;function foo(){}&lt;/code&gt; as a function declaration and then &lt;code&gt;()&lt;/code&gt; as a function call. Since they are not grouped, the function throws an error: &lt;code&gt;Uncaught SyntaxError: Unexpected token&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To fix this, we can call on the grouping operator &lt;code&gt;( )&lt;/code&gt; to group the function declaration and immediately invoke the function &lt;code&gt;(function foo(){ })()&lt;/code&gt; or group the entire function together with &lt;code&gt;(function foo(){ }())&lt;/code&gt; to create function expressions that can be immediately invoked.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's a typical use case for anonymous functions?
&lt;/h2&gt;

&lt;p&gt;IIFE which was mentioned above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//expression&lt;/span&gt;
    &lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As a callback where naming the function isn't necessary and it won't need to be used anywhere else(Yangshun's example):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What's the difference between host objects and native objects?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Native objects&lt;/strong&gt; are objects that are unique to the JavaScript language. Some examples include: String, Number, Array, Image, Date, Math, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Host objects&lt;/strong&gt; are objects that are supplied to JavaScript by the browser environment. Examples of these are window, document, forms, etc.&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quote from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE"&gt;https://developer.mozilla.org/en-US/docs/Glossary/IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://lucybain.com/blog/2014/immediately-invoked-function-expression/"&gt;http://lucybain.com/blog/2014/immediately-invoked-function-expression/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.quora.com/What-is-a-typical-usecase-for-anonymous-functions"&gt;https://www.quora.com/What-is-a-typical-usecase-for-anonymous-functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.sitepoint.com/oriented-programming-1-4/"&gt;https://www.sitepoint.com/oriented-programming-1-4/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>MJSQ 101: .call vs .apply, ternaries, and same-origin policy</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Wed, 29 Jan 2020 03:37:44 +0000</pubDate>
      <link>https://dev.to/danvyle/mjsq-101-call-vs-apply-ternaries-and-same-origin-policy-a8l</link>
      <guid>https://dev.to/danvyle/mjsq-101-call-vs-apply-ternaries-and-same-origin-policy-a8l</guid>
      <description>&lt;h3&gt;
  
  
  More JavaScript Questions 101(MJSQ 101):
&lt;/h3&gt;

&lt;p&gt;Continuing from my original &lt;a href=""&gt;blog post&lt;/a&gt;, more javascript 101 questions!:&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the difference between &lt;code&gt;.call&lt;/code&gt; and &lt;code&gt;.apply&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.call&lt;/code&gt; and &lt;code&gt;.apply&lt;/code&gt; are used to invoke functions. The first parameter will be the value to &lt;code&gt;this&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.call&lt;/code&gt; takes in comma-separated arguments as the next arguments &lt;br&gt;
&lt;code&gt;.apply&lt;/code&gt; takes in an array of arguments as the next argument&lt;/p&gt;

&lt;p&gt;User Yangshun gives a great tip to remember: &lt;br&gt;
C is for &lt;strong&gt;call&lt;/strong&gt; and &lt;strong&gt;comma-separated&lt;/strong&gt;&lt;br&gt;
A is for &lt;strong&gt;apply&lt;/strong&gt; and an &lt;strong&gt;array of arguments&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;teamScored&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;teamScored&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;It's a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;touchdown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// "It's a touchdown!"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;teamScored&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;It's a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;touchdown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]));&lt;/span&gt; &lt;span class="c1"&gt;// "It's a touchdown!"&lt;/span&gt;

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



&lt;h2&gt;
  
  
  Why is it called a Ternary expression, what does the word "Ternary" indicate?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ternary&lt;/strong&gt; indicates three. A ternary expression accepts three operands:&lt;br&gt;
1) the test condition&lt;br&gt;
 followed by a &lt;code&gt;?&lt;/code&gt;&lt;br&gt;
2) an expression to operate if the test condition is truthy&lt;br&gt;
 followed by a &lt;code&gt;:&lt;/code&gt;&lt;br&gt;
3) and expression to operate if the test condition is falsy&lt;/p&gt;

&lt;p&gt;This is commonly used to shorten up an &lt;code&gt;if&lt;/code&gt; statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;ballCrossedGoalLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isTouchdown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isTouchdown&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yes! It is a touchdown!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;No, the team was denied.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ballCrossedGoalLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;//output: "Yes! It is a touchdown!"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ballCrossedGoalLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;//output: "No, the team was denied."&lt;/span&gt;

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



&lt;h2&gt;
  
  
  Explain the same-origin policy with regards to JavaScript.
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;same-origin policy&lt;/strong&gt; prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of protocol, host, and URL port.  These three must be identical in the URLs that are used to access the content for them to be considered the same origin.&lt;/p&gt;

&lt;p&gt;The purpose of the &lt;strong&gt;same-origin policy&lt;/strong&gt; is to prevent scripts from accessing malicious content. Without the &lt;strong&gt;same-origin policy&lt;/strong&gt;, a script could open a new browser window and trick the user into accessing sensitive content. The script could then read the content and transmit it to another server. &lt;/p&gt;

&lt;p&gt;Here's a great explanation from It Pro Today: Let's say that a script hosted on myhost.com is embedded in a web page that's hosted on yourhost.com using the script element's src attribute. The origin of the script is yourhost.com. The origin of the script is the page's domain in which it's embedded. The script has full access to the content and properties of any page that's hosted on yourhost.com regardless of whether it's opened in new window or iframe. But if the script opens a new window and loads a document from myhost.com or any other domain, then the &lt;strong&gt;same-origin policy&lt;/strong&gt; comes into effect in which the script can't access the document's content or properties.&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quote from his github. Find his tech interview handbook &lt;a href=""&gt;here&lt;/a&gt; and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator"&gt;https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy"&gt;https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.itprotoday.com/web-application-management/javascript-same-origin-policy"&gt;https://www.itprotoday.com/web-application-management/javascript-same-origin-policy&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>More JavaScript 101: Module Patterns</title>
      <dc:creator>Dan-Vy Le</dc:creator>
      <pubDate>Tue, 21 Jan 2020 23:13:48 +0000</pubDate>
      <link>https://dev.to/danvyle/more-javascript-101-module-patterns-48pi</link>
      <guid>https://dev.to/danvyle/more-javascript-101-module-patterns-48pi</guid>
      <description>&lt;p&gt;Continuing from my previous &lt;a href=""&gt;blog post&lt;/a&gt;, more javascript 101 questions!:&lt;/p&gt;

&lt;h2&gt;
  
  
  Module Patterns
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Modules&lt;/strong&gt; are an integral piece of any robust application's architecture and typically help in keeping the units of code for a project both cleanly separated and organized. The Module Pattern is great for services and testing/TDD.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Module pattern&lt;/strong&gt; was originally defined as a way to provide both private and public encapsulation for classes in conventional software engineering. This helps reduce the chance of having conflicting function names with other functions in your code.&lt;/p&gt;

&lt;p&gt;Before ES6, modules looked similar to this, stating private variables first, &lt;code&gt;return&lt;/code&gt;ing variables to make them public and then immediately invoking them at the end with &lt;code&gt;()&lt;/code&gt; at the bottom.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// declare private variables and/or functions&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//declare public variables and/or functions&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

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



&lt;p&gt;After ES6, modules have been created to be accessible in classes in other files. private properties are established in the constructor and public methods are still below being &lt;code&gt;return&lt;/code&gt;ed. The class is created and you can export the class. It can then be imported in any other files for use. FreeCodeCamp has a great example of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//lib/module.js file&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ShoppingDataType&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//private Properties&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shoppingList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bananas&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;oranges&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apples&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// public methods&lt;/span&gt;
  &lt;span class="nx"&gt;getShoppingList&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shoppingList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;addItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shoppingList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;ShoppingDataType&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// main.js file&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ShoppingDataType&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lib/module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;shopping&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ShoppingDataType&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shopping&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getShoppingList&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There are many schools of thought on how to design your code in javascript and module patterns is just one. &lt;a href=""&gt;Click here for more information on other design patterns&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all for today, please leave any comments/questions/corrections in the comments. Thanks!&lt;/p&gt;

&lt;h6&gt;
  
  
  Sources:
&lt;/h6&gt;

&lt;p&gt;Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quote from his github. Find his tech interview handbook here and please support him!&lt;/p&gt;

&lt;p&gt;And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!&lt;/p&gt;

&lt;p&gt;Other sources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://coryrylan.com/blog/javascript-module-pattern-basics"&gt;https://coryrylan.com/blog/javascript-module-pattern-basics&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript"&gt;https://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=3pXVHRT-amw"&gt;https://www.youtube.com/watch?v=3pXVHRT-amw&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
