<?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: Nico Zerpa (he/him)</title>
    <description>The latest articles on DEV Community by Nico Zerpa (he/him) (@nicozerpa).</description>
    <link>https://dev.to/nicozerpa</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%2F592165%2F46614067-4880-40e4-bebd-74c6d7119182.png</url>
      <title>DEV Community: Nico Zerpa (he/him)</title>
      <link>https://dev.to/nicozerpa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nicozerpa"/>
    <language>en</language>
    <item>
      <title>What you have to learn before React</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Thu, 13 Apr 2023 16:34:30 +0000</pubDate>
      <link>https://dev.to/nicozerpa/what-you-have-to-learn-before-react-1pi7</link>
      <guid>https://dev.to/nicozerpa/what-you-have-to-learn-before-react-1pi7</guid>
      <description>&lt;p&gt;Learning front-end development is often overwhelming for beginners. Many of them want to learn React, but this question often keeps them from tackle the library. &lt;/p&gt;

&lt;p&gt;While you should be comfortable with some basic JS concepts, you don't necessarily need to be a JavaScript expert to learn React (or any other UI library). Actually, you can learn React as you continue learning JavaScript.&lt;/p&gt;

&lt;p&gt;You should have a good understanding of the fundamentals of JavaScript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_Types#variables"&gt;Variables&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_Types#data_structures_and_types"&gt;data types&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#conditional_statements"&gt;Conditionals&lt;/a&gt; (in particular the ternary operator)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration"&gt;Loops&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions"&gt;Functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects"&gt;Objects&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Arrays"&gt;arrays&lt;/a&gt; (note: in JavaScript, arrays are a type of object)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These syntatic aspects of the language are particularly important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment"&gt;Destructuring&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"&gt;Arrow functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax"&gt;Spread operator&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You should also be aware of these more advance topics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Immutable"&gt;Immutability&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nicozerpa.com/what-does-async-do"&gt;Asynchronous programming: promises, async/await&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules"&gt;Modules&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's also important to remember that you also need some knowledge of HTML and CSS. Again, you don't have to be an expert, but the more you know, the better.&lt;/p&gt;




&lt;p&gt;Become a Better JavaScript Developer! Easy, actionable steps to level up your JavaScript skills, right to your inbox. &lt;a href="https://nicozerpa.com/"&gt;Click here to subscribe!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Small trick to understand the `this` keyword</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Mon, 13 Feb 2023 15:00:00 +0000</pubDate>
      <link>https://dev.to/nicozerpa/small-trick-to-understand-the-this-keyword-184p</link>
      <guid>https://dev.to/nicozerpa/small-trick-to-understand-the-this-keyword-184p</guid>
      <description>&lt;p&gt;The &lt;code&gt;this&lt;/code&gt; keyword is one of the biggest headaches for anyone learning JavaScript. In this article, I won't go too deep into how the keyword works, but I will give you a quick tip to make it easier to handle.&lt;/p&gt;

&lt;p&gt;As a general rule, the &lt;code&gt;this&lt;/code&gt; keyword represents what's left of the dot when you're calling the method. Let's see an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Capybara&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;sayName&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="s2"&gt;`My name is &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;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="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;capyDavid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Capybara&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;David&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;capyArianna&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Capybara&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Arianna&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;capyDavid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// ☝️ "this" is `capyDavid`,&lt;/span&gt;
&lt;span class="c1"&gt;//    returns "My name is David"&lt;/span&gt;

&lt;span class="nx"&gt;capyArianna&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// ☝️ "this" is `capyArianna`,&lt;/span&gt;
&lt;span class="c1"&gt;//   returns "My name is Arianna"&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In JavaScript, functions are values. That is, you can pass functions as arguments, or assign them to variables. But when you do it, things get tricky:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayDavidName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;capyDavid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;sayDavidName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// ☝️ It fails! There's nothing "left of the dot"&lt;/span&gt;
&lt;span class="c1"&gt;//   because there's no dot.&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;quoteCapybara&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayNameFuntion&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="s2"&gt;`A capybara says: "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;sayNameFuntion&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;"`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;quoteCapybara&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;capyArianna&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ☝️ It fails too&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the last example (the &lt;code&gt;quoteCapybara&lt;/code&gt; function), why does it fail when you correctly passed the function as &lt;code&gt;capyArianna.sayName&lt;/code&gt;? Because the function is executed inside the &lt;code&gt;quoteCapybara&lt;/code&gt; function. There, it's run as &lt;code&gt;sayNameFunction&lt;/code&gt;, so there's nothing "left of the dot".&lt;/p&gt;

&lt;p&gt;In those cases, the most recommended solution is to change &lt;code&gt;quoteCapybara&lt;/code&gt; so that it receives the capybara object as the parameter. &lt;/p&gt;




&lt;p&gt;Become a Better JavaScript Developer&lt;br&gt;
Easy, actionable steps to level up your JavaScript skills, right to your inbox. &lt;a href="https://nicozerpa.com/newsletter" rel="noopener noreferrer"&gt;Click here to subscribe&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gratitude</category>
      <category>workplace</category>
      <category>career</category>
    </item>
    <item>
      <title>Don't add or change methods in built-in JavaScript objects</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Wed, 08 Feb 2023 16:11:33 +0000</pubDate>
      <link>https://dev.to/nicozerpa/dont-add-or-change-methods-in-built-in-javascript-objects-2ph2</link>
      <guid>https://dev.to/nicozerpa/dont-add-or-change-methods-in-built-in-javascript-objects-2ph2</guid>
      <description>&lt;p&gt;It is possible to add and modify properties and methods to JavaScript classes and prototypes using the &lt;code&gt;prototype&lt;/code&gt; property of the class or constructor function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Dog&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;bark&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Woof!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&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;// Add a new method to the Dog class&lt;/span&gt;
&lt;span class="nx"&gt;Dog&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="nx"&gt;howl&lt;/span&gt; &lt;span class="o"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ooowhooooooo!!!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though it is possible to use this to add more properties or methods to built-in objects (i.e. &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;String&lt;/code&gt;, etc.), it's generally a bad idea to do it.&lt;/p&gt;

&lt;p&gt;The problem is, when you make changes to a native object, you could cause weird bugs across the entire codebase, even in external libraries that your project uses. &lt;/p&gt;

&lt;p&gt;When you add a new method to a native object, there is the chance of name collisions: a native method with the same name might be added in the future.&lt;/p&gt;

&lt;p&gt;Those kinds of errors are very hard to find, especially if the developer who found the bug is not the one who changed the native object. They might assume that built-in objects were never modified (which if often the case) and they would take hours trying to debug.&lt;/p&gt;

&lt;p&gt;As I've read on other websites: built-in objects aren't your objects, they are everyone's objects. When you make changes to them, you also change everyone's code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the alternatives?
&lt;/h2&gt;

&lt;p&gt;There are a couple of alternatives to modifying built-in objects. If you add a small number of methods, you can simply create a regular function that takes the object instance as an argument.&lt;/p&gt;

&lt;p&gt;Another alternative is to create a new class that inherits from the built-in object. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ShufflableArray&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This method randomizes the elements in an array&lt;/span&gt;
    &lt;span class="nx"&gt;shuffle&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;copy&lt;/span&gt; &lt;span class="o"&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&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="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copyIndex&lt;/span&gt; &lt;span class="o"&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;floor&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;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;copyIndex&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;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
            &lt;span class="nx"&gt;index&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;array&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;ShufflableArray&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="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shuffle&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;array&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Outputs [4, 1, 3, 5, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Become a Better JavaScript Developer! Easy, actionable steps to level up your JavaScript skills, right to your inbox. &lt;a href="https://nicozerpa.com/newsletter"&gt;Click here to subscribe&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why I don't like front-end developer roadmaps</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Fri, 06 Jan 2023 16:11:59 +0000</pubDate>
      <link>https://dev.to/nicozerpa/why-i-dont-like-front-end-developer-roadmaps-5d98</link>
      <guid>https://dev.to/nicozerpa/why-i-dont-like-front-end-developer-roadmaps-5d98</guid>
      <description>&lt;p&gt;Development roadmaps are very common among those who want to become front-end developers. However, they are &lt;em&gt;freaking&lt;/em&gt; intimidating! &lt;a href="https://archive.is/wt5oZ" rel="noopener noreferrer"&gt;Look at this one, for example&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While the authors of those roadmaps have the best intentions, they may actually scare people and deter them from actually starting their learning journey.&lt;/p&gt;

&lt;p&gt;Another problem is that it makes people think that it's a completely linear process (i.e. that you have to master one topic before moving on to the next one). In many cases, that's not true.&lt;/p&gt;

&lt;p&gt;It's OK to learn a topic only partially and then move on to learn another language or technology. Every piece of knowledge is a tool: the more tools/knowledge you have, the more things you'll be able to do. But this also means that you can already build things with the knowledge/tools you already have.&lt;/p&gt;

&lt;p&gt;For those who are in their very early stages and want to become a front-end developer: I'd suggest to learn the basics of the following languages, tools, and libraries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP&lt;/li&gt;
&lt;li&gt;HTML and CSS&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;Git&lt;/li&gt;
&lt;li&gt;A front-end library or framework, preferably React because it's more widely used (and that means, there are more job offers)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Free JavaScript Newsletter! Every other Monday, easy and actionable steps to level up your JavaScript skills. &lt;a href="https://nicozerpa.com/newsletter" rel="noopener noreferrer"&gt;Click here to subscribe&lt;/a&gt;&lt;/p&gt;

</description>
      <category>community</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Can "Don't reinvent the wheel" be bad advice?</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Thu, 24 Nov 2022 15:59:37 +0000</pubDate>
      <link>https://dev.to/nicozerpa/can-dont-reinvent-the-wheel-be-bad-advice-ddm</link>
      <guid>https://dev.to/nicozerpa/can-dont-reinvent-the-wheel-be-bad-advice-ddm</guid>
      <description>&lt;p&gt;A very common programming tip is "Don't reinvent the wheel". If there's already a library that already does the task you need, why don't you just use that library instead of writing your own solution?&lt;/p&gt;

&lt;p&gt;Many times, it's a sensitive thing to do: importing third-party libraries lets you focus on other tasks. Also, if you're using a popular library that has been stable for years, it probably does the task better than you! However, using third-party components have drawbacks.&lt;/p&gt;

&lt;p&gt;The authors might deprecate the library or even delete it. Or the library (or any of their dependencies) might have a security problem and you have to wait until the authors fix it. Or they might even decide not to fix the security issue.&lt;/p&gt;

&lt;p&gt;In 2016, there was an NPM JS package called "left-pad", which was used as a dependency for thousands of projects. &lt;a href="https://www.theregister.com/2016/03/23/npm_left_pad_chaos/" rel="noopener noreferrer"&gt;One day, the original author deleted it and broke every single project that depended on it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another drawback may happen when your project changes after you used an external library. You may need to add new functionality that doesn't work with the library you added. Generally, this kind of problem can be solved, but it adds complexity to your project.&lt;/p&gt;

&lt;p&gt;I think "don't reinvent the wheel" is a good approach, but you have to be careful every time you add an external library to your project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the library you're adding is very big and you need a small part of it: it's probably a better idea to do it yourself or look for a smaller library.&lt;/li&gt;
&lt;li&gt;If the library has been popular for a long time, that's good. If you run into problems, you'll have a lot of documentation and help online.&lt;/li&gt;
&lt;li&gt;If the task is small or simple, it's a better idea to implement it yourself.&lt;/li&gt;
&lt;li&gt;If the task is very complex, looking for a library might be a good thing to do.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If you have to do tasks involving security (cryptography, passwords, hashes, etc) it's very recommended to use a trustworthy, third-party library.&lt;/strong&gt; Cyber security is a very complex field, if you try to create your own security-related tasks, it &lt;strong&gt;will&lt;/strong&gt; be insecure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To sum up: can "don't reinvent the wheel" be bad advice? The answer, as always, is: "it depends".&lt;/p&gt;




&lt;p&gt;If you liked this article, you'll love my JavaScript Newsletter.&lt;br&gt;
Every other Monday, I'll send you easy and actionable steps to level up your JavaScript skills. Check it out: &lt;a href="https://nicozerpa.com/newsletter" rel="noopener noreferrer"&gt;https://nicozerpa.com/newsletter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>tooling</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>10 beginner-friendly JavaScript projects</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Wed, 02 Nov 2022 15:58:09 +0000</pubDate>
      <link>https://dev.to/nicozerpa/10-beginner-friendly-javascript-projects-4nbg</link>
      <guid>https://dev.to/nicozerpa/10-beginner-friendly-javascript-projects-4nbg</guid>
      <description>&lt;p&gt;Programming is a skill and you need to practice if you want to become better at it. Creating your own projects is a fantastic way to practice your skill.&lt;/p&gt;

&lt;p&gt;However, many beginners don't know exactly what projects to create. That's why I created this list of 10 projects so that you can start coding.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Coin Toss
&lt;/h2&gt;

&lt;p&gt;For this project, you'll create a virtual coin that will display either "head" or "tails" randomly. Create a button "Toss the coin" that, well, tosses a coin 😅.&lt;/p&gt;

&lt;p&gt;When the user presses that button, use the method &lt;code&gt;Math.random()&lt;/code&gt; to determine whether to display "Heads" or "Tails" to the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Change background color (three inputs)
&lt;/h2&gt;

&lt;p&gt;In this project, the user will be able to change the page background color. Create three numeric inputs with the labels red, green, and blue. Also, add a button with the text "Change background color".&lt;/p&gt;

&lt;p&gt;The user should enter a number between 0 and 255 for the three inputs. And when they press the button, the background will change. It will take the red-green-blue values from what the user wrote.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. World Clock
&lt;/h2&gt;

&lt;p&gt;Create a text input and a submit button. There, the user should write the name of a time zone (&lt;a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List"&gt;Here's a list&lt;/a&gt;, look for the column "TZ database name").&lt;/p&gt;

&lt;p&gt;When the user presses the button, you should display the user the date and time in that time zone. You'll probably use a &lt;code&gt;Date&lt;/code&gt; object and its method &lt;code&gt;toLocaleString&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Article table of contents
&lt;/h2&gt;

&lt;p&gt;Pick up any article which has subtitles (like this one!) Copy the article and make sure that the subtitles have the &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; HTML tag.&lt;/p&gt;

&lt;p&gt;When the page loads, it should search for all the &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; tags in the page and create the list of all the subtitles. Add that list at the top of the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Calculator
&lt;/h2&gt;

&lt;p&gt;Create a basic calculator that can add, substract, multiply or divide numbers. Ideally, create the keys for the numbers and the operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Shopping cart
&lt;/h2&gt;

&lt;p&gt;Create a list of products, each of them with an "Add to Cart" button. Then, add another button "View Cart" that hides the list of products and lists only what you have in the cart.&lt;/p&gt;

&lt;p&gt;When you're viewing the cart contents, each item should have a "Remove from cart" button.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Pokedex
&lt;/h2&gt;

&lt;p&gt;If you're a Pokémon fan, create a Pokedex that displays a picture, the Pokedex number (i.e. the ID), the type, and abilities of a Pokémon.&lt;/p&gt;

&lt;p&gt;Create a text input where the user can write either the ID/National Pokedex number or lowercase name of a Pokémon.&lt;/p&gt;

&lt;p&gt;Then, use the &lt;a href="https://pokeapi.co/"&gt;PokéAPI&lt;/a&gt; web service to get the information about the Pokémon and display the information on screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Actually build the To Do app
&lt;/h2&gt;

&lt;p&gt;If you're learning a JavaScript framework which has a todo app in the documentation, try to replicate it yourself! You can also create it using Vanilla JavaScript, even though it might be a little harder.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Currency Converter
&lt;/h2&gt;

&lt;p&gt;For this project, you can use one of these two web services: &lt;a href="https://fixer.io/"&gt;https://fixer.io/&lt;/a&gt;, &lt;a href="https://exchangeratesapi.io/"&gt;https://exchangeratesapi.io/&lt;/a&gt;. These services are generally paid, but both have a free tier that you can use.&lt;/p&gt;

&lt;p&gt;The user should be able to select the currency of origin and write the amount to convert. Add a second select to let the user choose the destination currency.&lt;/p&gt;

&lt;p&gt;Add a button that calls the web services to convert the amount from the origin currency to the destination currency.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Clone your favorite web page/social network
&lt;/h2&gt;

&lt;p&gt;Pick any website you like and try to replicate its basic functionality.&lt;/p&gt;




&lt;p&gt;I have a Free JavaScript Newsletter with easy and actionable steps to level up your JavaScript skills. Subscribe here: &lt;a href="https://nicozerpa.com/"&gt;https://nicozerpa.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>TypeScript: why static typing matters</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Thu, 15 Sep 2022 16:34:28 +0000</pubDate>
      <link>https://dev.to/nicozerpa/typescript-why-static-typing-matters-444d</link>
      <guid>https://dev.to/nicozerpa/typescript-why-static-typing-matters-444d</guid>
      <description>&lt;p&gt;&lt;strong&gt;The biggest feature that TypeScript brings to the table is static types.&lt;/strong&gt; But, what are the advantages of static types over the dynamic typing in regular JavaScript?&lt;/p&gt;

&lt;p&gt;A very common type of bug in JavaScript and dynamic languages happens &lt;strong&gt;when you pass a variable with the wrong type or the wrong structure.&lt;/strong&gt; Those kind of errors are hard to catch before running the code. Also, the more complex the code is, the hardest it is to find those bugs.&lt;/p&gt;

&lt;p&gt;Strict typing practically eliminate the entire category of bugs. When you create methods and functions, it forces you to specify the data types for the parameters and you'll get errors if you call those functions using parameters with the wrong data types. In most code editors and IDEs, you'll get the error messages as you type.&lt;/p&gt;

&lt;p&gt;It also &lt;strong&gt;makes the code more "self-documented"&lt;/strong&gt;, as the type information makes it easier to understand how functions, classes and other structures work. If you have to refactor code or remove technical debt, this makes the task easier.&lt;/p&gt;

&lt;p&gt;Another advantage of static typing is that &lt;strong&gt;it integrates better with autocomplete tools&lt;/strong&gt;, making them more accurate and reliable. That makes you write code faster. Static-typed code is easier to read for humans and for robots!&lt;/p&gt;

&lt;p&gt;However, if you've never used a statically typed language before, it takes time to get used. At the beginning, it may feel limiting because you lose some flexibility. For example, you can't combine variables with two different data types that easily. But you can get used to it with enough practice.&lt;/p&gt;




&lt;p&gt;If you liked this article, you'll love my JavaScript Newsletter.&lt;br&gt;
Every other Monday, I'll send you easy and actionable steps to level up your JavaScript skills. Check it out: &lt;a href="https://nicozerpa.com/newsletter"&gt;https://nicozerpa.com/newsletter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why are there so many JavaScript frameworks?</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Mon, 22 Aug 2022 16:01:19 +0000</pubDate>
      <link>https://dev.to/nicozerpa/why-are-there-so-many-javascript-frameworks-47ag</link>
      <guid>https://dev.to/nicozerpa/why-are-there-so-many-javascript-frameworks-47ag</guid>
      <description>&lt;p&gt;Angular, React, Vue.js, Svelte... Next.js, Nuxt.js, Astro... Redux, Recoil, Zustand, MobX... &lt;strong&gt;the front-end JavaScript ecosystem is riddled with frameworks and libraries.&lt;/strong&gt; And every time you have to create a new project, you have to decide which ones to use. A daunting task, but why?&lt;/p&gt;

&lt;p&gt;The main problem is that &lt;strong&gt;it's hard to build and maintain complex front-end applications with vanilla JavaScript only.&lt;/strong&gt; That kind of apps has a lot of moving parts, and you, as the developer, have to take care of all those parts. Here's where the difficulty lies.&lt;/p&gt;

&lt;p&gt;Front-end libraries and frameworks were created to make building front-end apps easier. These take care of many of those moving parts, so that you have less on your plate. The thing is, these frameworks often have problems of their own.&lt;/p&gt;

&lt;p&gt;And that's why new frameworks emerge, &lt;strong&gt;they try to solve the problems created by older frameworks.&lt;/strong&gt; In general, newer libraries and frameworks are technically better than older ones.&lt;/p&gt;

&lt;p&gt;On the other hand, older frameworks/libraries have better ecosystems (i.e. more libraries and plugins), bigger communities and more documentation.&lt;/p&gt;

&lt;p&gt;It's a good idea to try new frameworks, but if you're creating a professional project, I recommend to rely on the most known ones, like React or Vue.js.&lt;/p&gt;




&lt;p&gt;If you liked this article, you'll love my JavaScript Newsletter.&lt;br&gt;
Every other Monday, I'll send you easy and actionable steps to level up your JavaScript skills. Check it out: &lt;a href="https://nicozerpa.com/newsletter"&gt;https://nicozerpa.com/newsletter&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript can speak! Using the Speech Synthesis API</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Wed, 03 Aug 2022 16:01:05 +0000</pubDate>
      <link>https://dev.to/nicozerpa/javascript-can-speak-using-the-speech-synthesis-api-5bo6</link>
      <guid>https://dev.to/nicozerpa/javascript-can-speak-using-the-speech-synthesis-api-5bo6</guid>
      <description>&lt;p&gt;A very underutilized feature in browsers is text-to-speech. With the Speech Synthesis API, &lt;strong&gt;you can use JavaScript to "make the browser talk".&lt;/strong&gt; Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&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;SpeechSynthesisUtterance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi! This is an example of the Speech Synthesis API&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en-US&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;voices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;speechSynthesis&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getVoices&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;voice&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;voice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en-US&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;voice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;voices&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="nx"&gt;speechSynthesis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View example live: &lt;a href="https://jsfiddle.net/holanicozerpa/4h2sf9gL/6/"&gt;https://jsfiddle.net/holanicozerpa/4h2sf9gL/6/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the example, one of the key parts of the Speech Synthesis API is the &lt;code&gt;SpeechSynthesisUtterance&lt;/code&gt; class. An object of this class represents the text that the browser will later read aloud.&lt;/p&gt;

&lt;p&gt;The other key part is the &lt;code&gt;speechSynthesis&lt;/code&gt; object. It's a global object that serves as the controller. This object, among other things, has a list of available voices. It also has the crucial &lt;code&gt;speak&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;When you create the &lt;code&gt;SpeechSynthesisUtterance&lt;/code&gt;, you can set the text in two ways. The first one is to put the text in the constructor (like in the example), and the second one is to use the &lt;code&gt;text&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;While it's not required, you should also set the language. This is to prevent international users listen to the text in the wrong language and incorrect pronunciation.&lt;/p&gt;

&lt;p&gt;In Firefox and Chrome, setting the text and the language is enough. If you use the &lt;code&gt;speechSynthesis.speak&lt;/code&gt; method, sending the utterance as a parameter, you will hear the text. But that probably won't work on Safari. You should also set which voice to use. &lt;/p&gt;

&lt;p&gt;Fortunately, you can use the &lt;code&gt;speechSynthesis.getVoices()&lt;/code&gt; method to get the list of available voices. It returns an array of &lt;code&gt;SpeechSynthesisVoice&lt;/code&gt; objects. Each of this object has a &lt;code&gt;lang&lt;/code&gt; property, and you should pick a voice with the same language as the utterance object.&lt;/p&gt;

&lt;p&gt;Lastly, you can associate the voice to the utterance object using the &lt;code&gt;voice&lt;/code&gt; property. Once you do that, speech synthesis will also work in Safari.&lt;/p&gt;




&lt;p&gt;If you liked this article, you'll love my JavaScript Newsletter.&lt;br&gt;
Every other Monday, I'll send you easy and actionable steps to level up your JavaScript skills. Check it out: &lt;a href="https://nicozerpa.com/newsletter"&gt;https://nicozerpa.com/newsletter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Strict mode in JavaScript</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Thu, 07 Jul 2022 16:20:04 +0000</pubDate>
      <link>https://dev.to/nicozerpa/strict-mode-in-javascript-22gd</link>
      <guid>https://dev.to/nicozerpa/strict-mode-in-javascript-22gd</guid>
      <description>&lt;p&gt;JavaScript wasn't originally created as a full-fledged programming language. It's original purpose was to add some interactivity to web pages. It was created as a very flexible language, forgiving to those who are new at programming.&lt;/p&gt;

&lt;p&gt;However, the language started to be use in more complex contexts, that "sloppiness" started to become a problem. Complex software requires language to be more restricted because it makes it easier to maintain.&lt;/p&gt;

&lt;p&gt;For that reason a new mode was introduced to the language, this is the strict mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to access strict mode
&lt;/h2&gt;

&lt;p&gt;One way to enable strict mode is by putting the string &lt;code&gt;"use strict";&lt;/code&gt; in the first line of the JavaScript file.&lt;/p&gt;

&lt;p&gt;Another way is to use native JavaScript modules. If you're using Node.js, modules are JS files with the filename extension &lt;em&gt;.mjs&lt;/em&gt; rather than &lt;em&gt;.js&lt;/em&gt;. In the browser, you should add the attribute &lt;code&gt;type="module"&lt;/code&gt; to the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;Code inside classes is always under strict mode too.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changes under strict mode
&lt;/h2&gt;

&lt;p&gt;Under the previous mode (often called "sloppy mode", but it's not an official name), you can create variables without declaring them with &lt;code&gt;const&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, or &lt;code&gt;var&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Stephanie&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="s2"&gt;`Her name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the old sloppy mode, the first line is correct, it creates a new variable called &lt;code&gt;name&lt;/code&gt;. But under strict mode, it throws an error.&lt;/p&gt;

&lt;p&gt;The problem with creating variables without declaring is that if you reassign an existing variable but you add a typo, you end up creating a new variable without realizing.&lt;/p&gt;

&lt;p&gt;Under sloppy mode, many errors were swept under the rug. They didn't work, but the code continued running as if nothing happened. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the examples above, you're messing with built-in objects and keywords of the language. You can't change or delete them, but in sloppy mode, these changes are ignored. If you run this code under strict mode, it will throw errors.&lt;/p&gt;

&lt;p&gt;Another big difference occurs with &lt;a href="https://nicozerpa.com/why-does-this-work-like-this"&gt;the &lt;code&gt;this&lt;/code&gt; keyboard&lt;/a&gt;. When you're calling a function which is not a method of any object, in strict mode the value of &lt;code&gt;this&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt;. Under "sloppy mode", the value of &lt;code&gt;this&lt;/code&gt; was the global object (i.e. in the browser, the &lt;code&gt;window&lt;/code&gt; object.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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;logThis&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="nx"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Outputs undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// sloppy mode&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;logThis&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="nx"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Outputs [object Window]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When to use it
&lt;/h2&gt;

&lt;p&gt;Nowadays, it's highly recommended that you always use strict mode. The only caveat is that if you are dealing with older code that doesn't use it, you shouldn't necessarily switch to strict mode until you fix all possible errors.&lt;/p&gt;




&lt;p&gt;If you liked this article, you'll love my JavaScript Newsletter.&lt;br&gt;
Every other Monday, I'll send you easy and actionable steps to level up your JavaScript skills. Check it out: &lt;a href="https://nicozerpa.com/newsletter"&gt;https://nicozerpa.com/newsletter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Should you use semicolons in JavaScript?</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Wed, 22 Jun 2022 16:12:57 +0000</pubDate>
      <link>https://dev.to/nicozerpa/should-you-use-semicolons-in-javascript-4io8</link>
      <guid>https://dev.to/nicozerpa/should-you-use-semicolons-in-javascript-4io8</guid>
      <description>&lt;p&gt;It's a topic that could seem trivial at first sight, but it actually causes some controversy among JavaScript developers. Semicolons, yes or no?&lt;/p&gt;

&lt;p&gt;The syntax of JavaScript, just like many other languages, is based on the &lt;a href="https://en.wikipedia.org/wiki/C_syntax"&gt;C programming language&lt;/a&gt;. In that language, semicolons are necessary to end a statement (i.e. an instruction.)&lt;/p&gt;

&lt;p&gt;But JavaScript interpreters use &lt;em&gt;Automatic Semicolon Insertion&lt;/em&gt;, a system that "inserts" semicolons before a line break in some circumstances. It doesn't literally insert it in the code, the interpreter acts as if there were a semicolon where ASI decides to.&lt;/p&gt;

&lt;p&gt;For example, In the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nico&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myLastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Zerpa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`My full name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;myLastName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ASI system will add semicolons after &lt;code&gt;"Nico"&lt;/code&gt; on line 1, after &lt;code&gt;"Zerpa"&lt;/code&gt; on line 2, and after the closing parenthesis on line 3.&lt;/p&gt;

&lt;p&gt;The exact rules of automatic semicolon insertion can be found on &lt;a href="https://262.ecma-international.org/12.0/#sec-automatic-semicolon-insertion"&gt;the official JavaScript/ECMAScript specification&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The problem is that omitting semicolons can lead to ambiguous code in some cases where ASI doesn't work as you may expect. Here's an example of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getData&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;49&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;favoriteFood&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pizza&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;melData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getData&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="s2"&gt;`Her name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;melData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,
  she's &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;melData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
  and she loves &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;melData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;food&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above doesn't work because ASI insert semicolons in an unexpected place: after the &lt;code&gt;return&lt;/code&gt; keyword on the second line. On top of that, the JS interpreter gets confused. Due to the added semicolon, it mistakenly thinks the object is a block of code. That triggers a syntax error.&lt;/p&gt;

&lt;p&gt;Those kind of problems could be solved if you simply learn when ASI inserts a semicolon. However, coding is almost always a team work. Even if you know the ASI rules by heart, other developers may not, and they could not read the code properly.&lt;/p&gt;

&lt;p&gt;For that reason, I decided to use semicolons. It's clearer for everyone, even for the JS interpreter.&lt;/p&gt;




&lt;p&gt;If you liked this article, you'll love my JavaScript Newsletter.&lt;br&gt;
Every other Monday, I'll send you easy and actionable steps to level up your JavaScript skills. Check it out: &lt;a href="https://nicozerpa.com/newsletter"&gt;https://nicozerpa.com/newsletter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript closures, explained</title>
      <dc:creator>Nico Zerpa (he/him)</dc:creator>
      <pubDate>Wed, 25 May 2022 12:26:27 +0000</pubDate>
      <link>https://dev.to/nicozerpa/javascript-closures-explained-46jn</link>
      <guid>https://dev.to/nicozerpa/javascript-closures-explained-46jn</guid>
      <description>&lt;p&gt;&lt;strong&gt;Closures are a concept that puzzle many JavaScript developers&lt;/strong&gt;, even after reading the zillion articles that have been written about the topic. Yes, this is just one of those zillion articles 😄, but I'll do my best to explain it.&lt;/p&gt;

&lt;p&gt;To explain what a closure is, first we have to explain the concept of &lt;em&gt;scope&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The scope indicates in which places a given variable is available.&lt;/strong&gt; Global variables (i.e. those not inside a function or block) are available everywhere in the code.&lt;/p&gt;

&lt;p&gt;If you create a new variable inside a function, the scope of that variable is the function itself, it's not available outside. And if you create one function inside another, the inner function can access the parent's variables.&lt;/p&gt;

&lt;p&gt;And if you create a variable using &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; inside a block of code enclosed in curly braces (&lt;code&gt;{&lt;/code&gt; and &lt;code&gt;}&lt;/code&gt;), those variables exist inside that block only.&lt;/p&gt;

&lt;p&gt;In JavaScript, functions can return another functions. When that happens, the new function can access the variable from its parent. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createLuckyNumberFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;luckyNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt; &lt;span class="o"&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;random&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="k"&gt;return&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;'s lucky number is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;luckyNumber&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="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;mikesLuckyNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createLuckyNumberFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mike&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="nx"&gt;mikesLuckyNumber&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// 👆 Outputs "Mike's lucky number is 3220"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;juliasLuckyNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createLuckyNumberFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Julia&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="nx"&gt;juliasLuckyNumber&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// 👆 Outputs "Julia's lucky number is 1449"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function &lt;code&gt;createLuckyNumberFunction&lt;/code&gt; (from now on, I'll call it the "parent function") create another function (the "child function") and returns it.&lt;/p&gt;

&lt;p&gt;The child function can access the variables from the parent, with the values they had when the child function was created.&lt;/p&gt;

&lt;p&gt;For example, the function that we get from the first call to &lt;code&gt;createLuckyNumberFunction&lt;/code&gt; has access to the variables &lt;code&gt;name = "Mike"&lt;/code&gt; and &lt;code&gt;luckyNumber = 3220&lt;/code&gt;. And the function from the second call can read the following variables: &lt;code&gt;name = "Julia"&lt;/code&gt; and &lt;code&gt;luckyNumber = 1449&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A closure is a combination between a function and its surrounding variables&lt;/strong&gt;. In this example, the closures are made of the inner function and the variables &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;luckyNumber&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Closures are useful when you want to hide variables and prevent them from being modified externally. In the examples above, nobody can change the lucky number after it was created.&lt;/p&gt;

&lt;p&gt;Another use is when the function will be executed in a different context (i.e. as a callback), but the function needs variables that may not be available at call time. &lt;/p&gt;




&lt;p&gt;If you liked this article, you'll love my JavaScript Newsletter.&lt;br&gt;
Every other Monday, I'll send you easy and actionable steps to level up your JavaScript skills. Check it out: &lt;a href="https://nicozerpa.com/"&gt;https://nicozerpa.com/&lt;/a&gt;&lt;/p&gt;

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