<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nicolle Romero on Medium]]></title>
        <description><![CDATA[Stories by Nicolle Romero on Medium]]></description>
        <link>https://medium.com/@nicollearomero?source=rss-1c30708f824d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*p3O2Agn2tMrau25yOmfXzw.png</url>
            <title>Stories by Nicolle Romero on Medium</title>
            <link>https://medium.com/@nicollearomero?source=rss-1c30708f824d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:56:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nicollearomero/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Learning a New Programming Language: Take the Plunge!]]></title>
            <link>https://blog.devgenius.io/learning-a-new-programming-language-take-the-plunge-97edf67f5e88?source=rss-1c30708f824d------2</link>
            <guid isPermaLink="false">https://medium.com/p/97edf67f5e88</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[hackbright-academy]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Nicolle Romero]]></dc:creator>
            <pubDate>Mon, 10 Aug 2020 04:19:22 GMT</pubDate>
            <atom:updated>2020-08-10T16:22:08.458Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_AZns5_6ODNxwdO6dqrcA.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@palumalerba?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Palu Malerba</a> from <a href="https://www.pexels.com/photo/photo-of-a-woman-diving-into-body-of-water-2516403/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>The first language you learn will naturally influence your coding journey, but your continued success may be limited if you are resistant to learning another language early in your career. As a beginner, picking up a second language may sound about as appetizing as taking the plunge into cold water, but you will ultimately be rewarded with a more solid understanding of CS fundamentals, command of a fuller stack, and better job prospects.</p><p>I began my coding journey by dipping a toe into JavaScript several years before transitioning fully into software engineering. Early on, I supplemented my learning by taking a Java course at a local college. Despite some frustration related to learning the quirks and new syntax when picking up another language, the overlap and contrast between the two languages provided a helpful perspective that highlighted the importance of many crucial computer science fundamentals.</p><p>The next part of my journey brought me to <a href="https://hackbrightacademy.com/">Hackbright Academy</a>, where I was challenged to learn a third language, Python. I’ll admit I was nervous about signing up to learn a new language in an already accelerated program, but the learning curve was definitely gentler with each subsequent language and learning Python amplified my experience at Hackbright.</p><h3>Adding to Your Toolbox</h3><p>Another benefit of learning a new language is that some languages are better suited for solving certain types of problems. Armed with several languages in your arsenal, you will have more tools at the ready when attempting difficult problems. This is especially true when learning a structurally different language. If you started with JavaScript or Python, it might be helpful to pick a lower-level language to learn next, such as C. If your emphasis has mostly been front-end, you may benefit from learning some Java, and in turn, may find that it supports an understanding of other strongly typed languages (which could make learning TypeScript easier).</p><p>The paths are varied, but learning any new language will both reinforce your current understanding of CS fundamentals and pave the path to exploring additional languages in the future. Being a lifelong learner is one common characteristic shared by all successful software engineers.</p><h3>Overcoming a Fear of Syntax</h3><p>You probably recall that tackling your first language involved multiple levels of learning: mastering the syntax of the language, getting comfortable with algorithmic thinking, and adopting a frame of mind that is conducive to programming. The sweetness experienced when all these aspects converge to allow you to enter a <em>programming flow</em> for the first time is a memorable feeling for every developer.</p><p>When learning your second language, many of these aspects are already established and this existing foundation allows you to narrow your focus on getting comfortable with the new syntax elements. This may be surprisingly easy the second time around: using curly braces instead of colons? No problem, your underlying understanding of the semantics is already there! You’ll certainly forget a semicolon or two when first coding in JavaScript, but learning the syntax will be a gentle slope instead of the cliff you scaled learning the full gamut of programming grammar the first time around. 🧗🏻‍♀️</p><h3>Embracing Full-Stack Engineering</h3><p>Accepting the challenge to learn a second or third language will inevitably make you a more confident and versatile developer, and with more than 500 programming languages out there, there’s a lot to choose from. Most companies now include multiple languages in their stacks, and it’s normal for these companies to require their engineers to be multi-lingual (with a few exceptions).</p><p>Take a look at the trends in the top 10 languages over the last five years as reported by GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*DUP5I9Xjm8-kHuuatR_ESw.png" /><figcaption><a href="https://octoverse.github.com/#top-languages">https://octoverse.github.com/#top-languages</a></figcaption></figure><p>A multi-lingual applicant will have access to a larger swath of job opportunities and will be able to demand a higher salary than job applicants that are less versatile. This is especially true for applicants looking to land a junior SWE position where the competition is tough and the ability to master multiple languages will evidence your capacity to learn and your ability to grow as a developer.</p><p>Don’t let the fear of the unknown stop you from learning a new language early in your career. The benefits of taking this step will compound, providing both obvious and some less obvious advantages along the way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97edf67f5e88" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/learning-a-new-programming-language-take-the-plunge-97edf67f5e88">Learning a New Programming Language: Take the Plunge!</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Scope Can Be Dicey]]></title>
            <link>https://blog.devgenius.io/javascript-scope-can-be-dicey-12a9f48bf328?source=rss-1c30708f824d------2</link>
            <guid isPermaLink="false">https://medium.com/p/12a9f48bf328</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nicolle Romero]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 02:50:53 GMT</pubDate>
            <atom:updated>2020-08-08T08:56:00.284Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding scope can help you avoid the dreaded <em>code smell.</em> Let’s peel back the layers of scope—global, local, function, and block — in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*IjDhAjpgS7YSfckEhK9LlQ.png" /></figure><p>Learning the rules of scope (especially in JavaScript) can be harrowing for any new developer, and can continue to plague even seasoned developers. Debugging code that suffers from <em>code smell</em> can often uncover a superficial understanding of scope (something far worse than that notorious onion stink). I’ll pause with the onion analogies and dive right in.</p><p>Understanding scope at the highest level when working in a single module is a good starting point:</p><ol><li>Scope describes what part of a program can <strong>access</strong> a specific variable.</li><li>A variable can have either <strong>global</strong> or <strong>local</strong> scope, depending on where and how it is declared.</li></ol><p>A global variable can be accessed from anywhere within a program. That means you can retrieve and reassign global variables from anywhere in the program without issue. (Well, that might be overstating it… variable shadowing <em>can</em> affect your ability to access a variable in an outer scope. You can read a more detailed description on how to avoid variable shadowing <a href="https://medium.com/dev-genius/foxy-javascript-a647f9a18dc2">here</a>.) Global variables can be declared anywhere in your program, and can be declared with the let or const keywords (var is also an option, but comes with its own caveats) as long as they are not declared within a function or block .</p><pre>let veggies = [&#39;garlic&#39;, &#39;cabbage&#39;, &#39;celery&#39;];</pre><pre>if (true) {<br>  veggies.push(&#39;onion&#39;);<br>}</pre><pre>console.log(veggies);<br> <br>// ⟶ [&#39;garlic&#39;, &#39;cabbage&#39;, &#39;celery&#39;, &#39;onion&#39;];</pre><p>In the example above, the variable veggies is in the global scope, and is referred to as a “global variable.”</p><p>Variables that are not globally scoped, are said to have <strong>local scope</strong>, and local scope can take one of two forms:</p><ol><li><strong>Function scope</strong>: variables defined within a function body are said to have function scope and are only accessible from within that function.</li><li><strong>Block scope</strong>: blocks are considered code statements grouped by opening and closing curly braces { }. We see blocks defined most often with the use of if/else, for loops, and while loops.</li></ol><p>The following example illustrates function scope:</p><pre>let veggies = [&#39;garlic&#39;, &#39;cabbage&#39;, &#39;celery&#39;, &#39;onion&#39;];</pre><pre>function chop(food) {  </pre><pre>  let dinner = food.slice(0, 2);<br>  <br>  veggies = food.slice(2);</pre><pre>  return dinner;<br>}</pre><pre>chop(veggies);</pre><pre>console.log(dinner);    // <em>ReferenceError: dinner is not defined</em></pre><pre>console.log(veggies);    <em>// [&#39;celery&#39;, &#39;onion&#39;];</em></pre><p>In the example above, the variable veggies is in the global scope and can be accessed from anywhere in the code, whereas the variable dinner has local scope because it is declared within the function body for chop. Notice that we can access and reassign veggies within the function and those changes persist outside of the function scope.</p><p>It works similarly for block scope:</p><pre>let veggies = [&#39;garlic&#39;, &#39;cabbage&#39;, &#39;celery&#39;, &#39;onion&#39;];</pre><pre>for (let veggie of veggies) {<br>  let firstLetter = veggie[0];<br>  let dinner = [];</pre><pre>  if (firstLetter !== &#39;c&#39;) {<br>    dinner.push(veggie);<br>  } else {<br>    let scrap = veggie;<br>    console.log(scrap);<br>  }<br>}</pre><pre>console.log(dinner);    // <em>ReferenceError: dinner is not defined</em></pre><pre>console.log(scrap);    // <em>ReferenceError: scrap is not defined</em></pre><p>Trying to access dinner outside of its local scope (the for block) results in a reference error because dinner is not accessible outside of that block.</p><p>Notice that in the example above, we have two blocks: a for block and nested inside of that, the if/else conditional block. Like peeling back the layers of an onion, you’ll see that a variable’s scope is further defined by <strong>nesting</strong>: variables declared in the inner-most layer of a nested function or a nested block can only be accessed from that inner-most layer. In the example above, the variable scrap is only accessible in the if/else block after it is declared.</p><p>While it can be said that a variable’s scope is all relative, it’s a little easier to understand than the theory or relativity (I hope!). Let’s give it a try:</p><ul><li>Variables declared in the inner-most block (like scrap) can access variables from <strong>any</strong> outer scope, including variables in the global scope.</li><li>Outer blocks <strong>cannot</strong><em> </em>access variables declared in any inner scopes (nested deeper than that block). So trying to access dinner or scrap from the global scope throws an error.</li></ul><p>It’s good to be aware that variables in an outer scope not only can be accessed by an inner scope, they can also be mutated or reassigned. This is another great reason to avoid short or vague variable names. (It’s not an issue when two functions or two blocks at the same level use the same variable name, also known as <em>peer scope</em>, but it could make your code more difficult to read.)</p><p>It’s also important to consider scope when addressing requirements. If a function should be designed to return a specific variable, it’s important to consider the ramifications of scope when considering these requirements. In the example below, where should the missingItems array be declared?</p><pre>let dinner = [&#39;garlic&#39;, &#39;cabbage&#39;, &#39;celery&#39;, &#39;onion&#39;];<br>let foodWeHave = [&#39;cabbage&#39;, &#39;celery&#39;];</pre><pre>function makeGroceryList(meal, food) {</pre><pre>  for (let veggie of dinner) {<br>    if (!foodWeHave.includes(veggie)) {<br>       missingItems.push(veggie);<br>    }<br>  }<br>  return missingItems;<br>}</pre><pre>console.log(makeGroceryList(dinner, foodWeHave));</pre><p><strong>Answer:</strong> the variable missingItems should be declared on the line immediately following the function declaration because it needs to be accessible at the function scope level in order to be accessible in the return statement. (This will also mean it is accessible to the nested for and if blocks.) It probably doesn’t need to be in the global scope if missingItems is only needed as part of the makeGroceryList function.</p><p>Like an onion, scope can reduce some to tears. Carefully tracking a variable’s scope, remembering to always explicitly declare variables, and being intentional when naming your variables can help avoid any meltdowns. Finally, it’s a good time to revisit variable shadowing and global scope pollution if you’re not yet familiar with these concepts. It might be tempting to reuse variable names and to declare most of your variables in the global scope, but that can lead to unexpected bugs and make your code difficult to test. You can find summaries of each of these pitfalls <a href="https://medium.com/dev-genius/foxy-javascript-a647f9a18dc2">here</a>.</p><p>Any way you slice it, understanding scope in JavaScript will save you (and your team) from the dreaded code smell that can result from poor practices when it comes to being careless with scope. &lt;/analogy&gt;</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12a9f48bf328" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/javascript-scope-can-be-dicey-12a9f48bf328">JavaScript Scope Can Be Dicey</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Foxy JavaScript]]></title>
            <link>https://blog.devgenius.io/foxy-javascript-a647f9a18dc2?source=rss-1c30708f824d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a647f9a18dc2</guid>
            <category><![CDATA[syntax]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicolle Romero]]></dc:creator>
            <pubDate>Wed, 27 May 2020 18:20:14 GMT</pubDate>
            <atom:updated>2020-06-02T20:31:35.620Z</atom:updated>
            <content:encoded><![CDATA[<p>How to outfox some of the trickiest aspects of the language</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-kIJ2nSl6dwz0bQ0O-K01A.png" /><figcaption>Photo by Alex Andrews from <a href="https://www.pexels.com/photo/photo-of-fox-sitting-on-ground-2295744/">Pexels</a></figcaption></figure><p>It’s common knowledge that JavaScript is a highly nuanced, fast and loose programming language that can result in some head shaking results.</p><p>Based on my journey into the language so far, this is what I’ve observed are the <strong>Top 10 Slyest Quirks of JavaScript.</strong></p><p><strong>#1 Implicit Coercion</strong></p><p>Notably, this quirk is one of the most infamous parts of the language. To oversimplify, implicit coercion is JavaScript’s ability (or deranged propensity?) to coerce one value type to another type. Some would argue that the value is coerced to the <em>expected</em> type. We get these fun little nuggets as a result of implicit coercion:</p><pre>1 &lt; 2 &lt; 3;    // --&gt; true </pre><pre>// but...   </pre><pre>3 &gt; 2 &gt; 1;    // --&gt; false</pre><pre>9 + &#39;1&#39;       // --&gt; &#39;91&#39;</pre><pre>// but...</pre><pre>91 - &#39;1&#39;      // --&gt; 90</pre><p>It gets even odder when working with arrays:</p><pre>[] == ![];      // --&gt; true</pre><pre>true == [];     // --&gt; false<br>true == ![];    // --&gt; false<br><br>false == [];    // --&gt; true<br>false == ![];   // --&gt; true</pre><p>Head-scratching for sure. There’s actually some interesting logic behind these coercions (based on the operation being performed and the operand types that are involved), but it’s pretty opaque to someone new to the language. If you get some surprising results, be on the lookout for this (and better yet, test any questionable operations being performed in your handy REPL). Also, get in the habit of using the strict equality operator === when comparing values or checking a variable’s type with the typeof keyword.</p><p><strong>#2 Semicolons</strong></p><p>This is a touchy subject, but for the beginner programmer, it’s more than an annoyance. It’s difficult to know when <em>not</em> using them will cause your code to implode. So, we’ve had the fear of God scared into us, and we just add them religiously. Point taken.</p><p>Take a look at this example:</p><pre>let students = &#39;&#39;</pre><pre>[&#39;Sam&#39;, &#39;Ari&#39;, &#39;Sharon&#39;, &#39;Steve&#39;].forEach((name) =&gt; {</pre><pre>    if (name !== &#39;Steve&#39;) {<br>      name += &#39; &amp; &#39;;<br>    }</pre><pre>    students += name;</pre><pre>});</pre><pre>console.log(students);</pre><pre>// expected: &#39;Sam &amp; Ari &amp; Sharon &amp; Steve&#39;</pre><p>Instead of the expected output of a string with alternating names and ampersands, it throws the error “<em>Cannot read property ‘forEach’ of undefined</em>.” Because a semicolon is missing from the end of the first line, the code is not parsed correctly, and the first line essentially bleeds into the second line:</p><pre>let students = &#39;&#39;[&#39;Sam&#39;, ... ].forEach(...)</pre><p>To avoid this issue, you need get in the habit of terminating every statement with a semicolon. Period. (Or, I guess, semicolon?)</p><p>#3 <strong>Elusive Return Values</strong></p><p>“<em>Question</em>: What does this function return?”</p><p>“Answer: A new array? Itself, just mutated? The length of the array? Undefined?”</p><p>Some methods, such as <em>Array.prototype.map()</em> and <em>Array.prototype.filter()</em> return a brand new array of elements with the intended changes implemented in the new array. Great! Just as we expected.</p><p>Other methods, such as <em>Array.prototype.sort()</em> and <em>Array.prototype.reverse()</em> mutate and then return the original array. As a n00b, how do you know exactly what a method will return? Well, there’s no easy way to know what a method will return unless you commit it to memory or look it up (or test it in your REPL). Honestly, it has more to do with <em>when</em> the methods were added to the language than the underpinnings of the methods themselves, but a little consistency would be a welcome relief to someone new to the language. &lt;/gripe&gt;</p><p><strong>#4 <em>Array.prototype.forEach()</em> and <em>Array.prototype.reduce()</em></strong></p><p>You know that awkward moment when you bring something up at a party that makes everyone in a previously chatty group go quiet? Say something strongly worded about either of these methods at a local JS Meetup, and you’ll know what I mean.</p><p>This is an interesting dilemma, and it might be too early for a developer to pick a side if they’re just getting their feet wet. Some argue that <em>forEach</em> is problematic because it primarily relies on side effects to get the job done. Case in point, it’s important to note (and commit to memory) that <em>forEach</em> always returns… undefined (surprise!) and not itself, so you can’t chain it like many other array methods. This may come back to bite you at some point. From a best practices standpoint, other methods that don’t depend on side effects (e.g., changes in state that don’t depend directly on the function inputs), are easier to read and predict because they have clear semantic meaning. In this case, less is more.</p><pre>let newArr <strong>=</strong> [];<br><br>[1, 2, 3].forEach((element) =&gt; {<br>  if(element &gt; 1) {<br>    newArr.push(element);<br>  }<br>});<br><br>console.log(newArr); // [2, 3]</pre><p>Compare this to the same task using <em>Array.prototype.filter()</em>:</p><pre>let newArr <strong> </strong>= [1, 2, 3].filter((element) =&gt; element &gt; 1);</pre><pre>console.log(newArr); // [2, 3]</pre><p><em>Array.prototype.reduce()</em> is an interesting, and powerful method, but some would argue that it makes the code more difficult to parse (for humans). It essentially “reduces” an array down to a single output value. This can make calculating a sum or removing duplicates from an array very streamlined, but it comes at the expense of less readable code. I think it’s valuable to become familiar with the method, but keep the pros and cons in mind.</p><p><strong>#5 Spread Operators (AKA “…”)</strong></p><p>This is the perfect syntax to use if you want to build anticipation...</p><p>All joking aside, the spread operator is useful, but it’s not super clear when it should be used. MDN states:</p><blockquote><strong>Spread syntax</strong> allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.</blockquote><p>The spread operator performs differently in different contexts. Here are just a few situations where you’ll find the spread syntax useful.</p><ul><li>It effectively “spreads” an array (or more than one array) into separate arguments when used in a function call. For example, when calling <em>Math.max() or Math.min()</em>:</li></ul><pre>let arr = [1, 3, 2, 0];</pre><pre>Math.max(...arr);  // 3</pre><ul><li>With more than one array:</li></ul><pre>let arr1 = [-1, -2, -3, -4];<br>let arr2 = [10, 3, -8, 1, 9];<br><br>Math.max(...arr1, ...arr2) ); // 10</pre><ul><li>Or it can be used to easily copy an array:</li></ul><pre>let arr = [1, 2, 3];</pre><pre>let newArr = [...arr];</pre><pre>console.log(newArr); //  [1, 2, 3]</pre><pre>arr === newArr; // false</pre><ul><li>It can also be used to expeditiously split a string into an array:</li></ul><pre>let string = &quot;Hello!&quot;;<br><br>console.log( [...string] ); // [ &#39;H&#39;, &#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;, &#39;!&#39;]</pre><p>It’s important to distinguish the <em>spread operator</em> from a different construct, <em>rest parameters</em>, since they both use the same syntax of &quot;...&quot; .</p><ul><li>Rest parameters are used in functions to allow them to accept any number of arguments. You can spot rest parameters when they’re used at the end of function parameters when a function is declared.</li><li>Spread syntax is used when passing in an array (or multiple arrays) during a function call.</li></ul><p><strong>#6 Implied Globals</strong></p><p>New programmers are continually warned not to “pollute the global scope,” but what exactly does that mean and how does the concept of implied globals play into that? When variables or functions are inadvertently named the same thing in the global scope, we refer to the problem that causes as <em>name collision</em>. This can happen when multiple teams are contributing code to the same project. Projects are prone to name collision if too many variables and functions are added to the global namespace, also referred to “polluting the global scope.”</p><p>To make matters worse, you can very easily add variables to the global scope unintentionally due to the occurrence of <em>implied globals</em>. Basically, if you don’t follow best practices and forget to explicitly declare your variable, it is interpreted by the language that you <em>meant </em>to declare it as a global variable:</p><pre>You type:</pre><pre>sum = 10;</pre><pre>JS interprets that as:</pre><pre>const sum = 0;</pre><p>Or another example (of chaining variable assignments):</p><pre>const findSum = (a, b) =&gt; {</pre><pre>  let sum = total = a + b; </pre><pre>};</pre><p>In this example, <em>sum</em> is scoped as a local variable, whereas <em>total</em> is scoped as a global variable. Oops.</p><p>Word to the wise: define each variable explicitly and keep your global scope tidy.</p><p><strong>#7 Double NOTs</strong></p><p>Despite there being a perfectly acceptable and <em>readable</em> built-in Boolean function (which casts most anything to a boolean), the double not, or !! is clear as mud. It also forces a value to a boolean:</p><pre>!!0 <br>!!null<br>!!undefined</pre><pre>...all return the boolean <strong>false</strong>. Nifty.</pre><p>Here’s a joke that helps explain it:</p><blockquote>A linguistics professor once said “A double negative forms a positive, while in some languages, a double negative is still a negative. However, there is no language wherein a double positive can form a negative.”</blockquote><blockquote>A voice from the back of the room piped up, “Yeah, right.”</blockquote><p>In a nutshell, the first ! converts the value into a boolean and it returns the inverse. The second ! will inverse <em>that</em> boolean, and in this convoluted manner, it converts the value to a boolean.</p><p>Can’t hardly find no fault in that.</p><p><strong>#8 Variable Shadowing</strong></p><p>This quirk isn’t unique to JavaScript, but it will get new programmers every time. It’s taught that you should pick the most descriptive variable names as possible, but what if that leads you to use the same variable name to declare a variable in the global scope and again in the local scope? That’s when it gets messy. The locally scoped variable essentially shadows, or overrides the previously scope global variable. Here’s an example:</p><pre>let num = 3;</pre><pre>function example() {<br>    let num = 1;<br>    num += 10;<br>    return num;</pre><pre>}</pre><pre>console.log(num);  // 3</pre><p>Did you expect to see an output of 11? In variable shadowing, if you declare a variable by the same name in both the local and global scope, the local variable will take precedence when you use it within a function. Shadowing can make reading code confusing and it also makes it impossible to access the global variable from within the function scope. Linters often have a “no-shadow” rule for good reason. Beware of lurking variable shadowing.</p><p><strong>#9 Hoisting</strong></p><p>For me, this term always invokes the image of a horse in a gurney (Phish fans?). It doesn’t sound elegant, but it’s a powerful part of the JavaScript language: no matter where variables are declared within a particular scope (local or global), all variable declarations are moved to the top of their scope. Like something out of Inception, it means that variable declarations are always processed before any code is executed (only applies to the declaration, not the assignment).</p><p>Related to #8 above, this can catch some developers off guard. It can lead to behaviors that you weren’t expecting if you’re unaware of hoisting: rather than being available only after their declaration, variables and functions might be available beforehand in the code, which might have some unanticipated consequences (both positive and negative).</p><p>For this reason, it’s advisable to get in the habit of declaring all variables at the top of their scope (for global scope or at the top of the local function scope).</p><p><strong>#10 Using <em>typeof</em> on null results in “object”</strong></p><p>smh…</p><p>Honestly, this is just accepted as a bug in the language, but if you’re curious about the history of it, you can find out more <a href="https://bitsofco.de/javascript-typeof/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a647f9a18dc2" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/foxy-javascript-a647f9a18dc2">Foxy JavaScript</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>