<?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>Forem: codeToBug</title>
    <description>The latest articles on Forem by codeToBug (@codetobug).</description>
    <link>https://forem.com/codetobug</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%2F1086886%2Ffbaad350-a554-4529-bd34-32dbe9dba0b5.jpg</url>
      <title>Forem: codeToBug</title>
      <link>https://forem.com/codetobug</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codetobug"/>
    <language>en</language>
    <item>
      <title>Injecting Dependency Like You've Never Seen Before: Unprecedented Laravel Missteps</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Tue, 13 Jun 2023 21:42:01 +0000</pubDate>
      <link>https://forem.com/codetobug/injecting-dependency-like-youve-never-seen-before-unprecedented-laravel-missteps-5e74</link>
      <guid>https://forem.com/codetobug/injecting-dependency-like-youve-never-seen-before-unprecedented-laravel-missteps-5e74</guid>
      <description>&lt;p&gt;Ah, the majestic art of Dependency Injection in Laravel – when executed flawlessly, it's like watching a ballet dancer pirouette gracefully. However, when it goes wrong, it's a hip-hop dancer in a ballet class, utterly hilarious.&lt;/p&gt;

&lt;p&gt;Isn't it simply the most elegant thing in the world, that thing we call Dependency Injection? When you inject the class into your Laravel controller, it's supposed to glide smoothly, like a well-oiled machine. Alas! Some of us seem to be making steam engines instead.&lt;/p&gt;

&lt;p&gt;Picture this: You're in the code wilderness, on a quest to instantiate that tricky Repository class. You've heard tales of Laravel's magical service container, its mystical powers of automatic resolution. &lt;strong&gt;But no, you say, "I’m not a magician! I am but a simple artisan."&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&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;Repository&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;Oh, a standing ovation for your courage, good sir/madam! Who needs Laravel's automatic resolution when you can manually do it yourself? It's like driving a Tesla but insisting on turning the ignition key that doesn't exist.&lt;/p&gt;

&lt;p&gt;Now let's up the ante. Ever stumbled upon the folks who like to treat Laravel like it's a one-man show, pushing all dependencies into a single method?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;overworkedFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Foo&lt;/span&gt; &lt;span class="nv"&gt;$foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Bar&lt;/span&gt; &lt;span class="nv"&gt;$bar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Baz&lt;/span&gt; &lt;span class="nv"&gt;$baz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Quux&lt;/span&gt; &lt;span class="nv"&gt;$quux&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Quuz&lt;/span&gt; &lt;span class="nv"&gt;$quuz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Corge&lt;/span&gt; &lt;span class="nv"&gt;$corge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Grault&lt;/span&gt; &lt;span class="nv"&gt;$grault&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Garply&lt;/span&gt; &lt;span class="nv"&gt;$garply&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Sincerely hoping the function does not collapse under pressure!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bravo! Look at this function, trying to juggle like a circus performer. It's not a function anymore, it's a dependency party and everybody's invited!&lt;/p&gt;

&lt;p&gt;I implore you, friends. Laravel, with its service container, is more like a magical butler. Its sole purpose is to elegantly manage our dependencies. Don't reduce it to a simple valet, carrying around your piles of objects. Let it shine in its true glory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Repository&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$repository&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;Behold the glory of a well-implemented constructor injection, the kind that doesn't make Laravel shed a tear behind the scenes.&lt;/p&gt;

&lt;p&gt;And that, ladies and gentlemen, is our comedy of errors, a true 'how-not-to' guide on Dependency Injection in Laravel. While these examples might make you laugh (or cry, if you're a true Laravel enthusiast), remember the golden rule: Keep It Simple, Silly. That's what Laravel is all about. Now, let's put our hands together for the unsung heroes of Laravel who keep the dependencies flowing smoothly, and the code bugs at bay.&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>When JavaScript Thinks You're Imagining Things: An Unexpected Tale of Non-Existent References</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Tue, 13 Jun 2023 21:28:27 +0000</pubDate>
      <link>https://forem.com/codetobug/when-javascript-thinks-youre-imagining-things-an-unexpected-tale-of-non-existent-references-oip</link>
      <guid>https://forem.com/codetobug/when-javascript-thinks-youre-imagining-things-an-unexpected-tale-of-non-existent-references-oip</guid>
      <description>&lt;p&gt;Are you a coder? Have you ever referenced an object in JavaScript only for it to reply with a blank stare? Today, we dive into the thrilling world of &lt;strong&gt;ReferenceError: Undefined is not an object&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ah, JavaScript, that ever-loyal friend who assures you it understands, only to freeze up and sputter "Huh, what's that?" when you ask it to fetch an object or property that, in its humble opinion, doesn't exist. Yes, my friend, today we discuss the notorious: ReferenceError: Undefined is not an object. We’ve all been there, haven't we?&lt;/p&gt;

&lt;p&gt;You know the scene. It's 2 a.m., the glow of your laptop screen illuminates the room, the keyboard's soothing click-clack is the only sound that can be heard, except for the quiet sobs of your sanity trickling away as you wrestle with this peculiar JavaScript foible.&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="nx"&gt;myCar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fast&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;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voilà! JavaScript, ever the vigilant guard of reality, snaps at you, "Wait a minute, partner. myCar doesn't have a weight property. I'm not going to let you just make things up here!" It may seem like JavaScript is throwing a tantrum, but really, it's just being a stickler for the rules. Adorable, isn't it?&lt;/p&gt;

&lt;p&gt;The code above is a common enough sight, one that makes seasoned developers sigh deeply while simultaneously popping another antacid. You see, JavaScript, despite its friendly demeanor, is a strict grammar teacher when it comes to the English language. If it doesn't see an object or property listed, it doesn't exist. Full stop. No further discussion.&lt;/p&gt;

&lt;p&gt;The remedy to such hilarity is quite simple. You, like a determined detective, must go back through your code, sifting through the lines of text until you spot the offending piece of errant referencing. Could it be a typo? A forgotten definition? Or maybe a promise to a variable that you never fulfilled? Who knows what mysteries await in the depths of your script.&lt;/p&gt;

&lt;p&gt;So, next time you face this error, take a moment to appreciate JavaScript's fierce commitment to reality. It's not trying to make your life difficult, it's just committed to the truth. It might even teach you a thing or two about managing expectations - a priceless life lesson served with a side of code debugging.&lt;/p&gt;

&lt;p&gt;As we bid adieu, &lt;strong&gt;remember - in the strange land of JavaScript, 'undefined' is more than just a state, it's a way of life&lt;/strong&gt;. Embrace the quirks, question your assumptions, and above all, enjoy the ride.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Tripping Over Code: An Amusing Exploration of Beginner JavaScript Blunders</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Thu, 08 Jun 2023 16:20:53 +0000</pubDate>
      <link>https://forem.com/codetobug/tripping-over-code-an-amusing-exploration-of-beginner-javascript-blunders-3413</link>
      <guid>https://forem.com/codetobug/tripping-over-code-an-amusing-exploration-of-beginner-javascript-blunders-3413</guid>
      <description>&lt;p&gt;Are you just dipping your toes into the ocean of JavaScript? Brace yourself for some unexpected trips over the most deceptive pebbles.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Hide and Seek Game of "this"
&lt;/h2&gt;

&lt;p&gt;JavaScript's "this" is a bit of a chameleon, often referred to as the "Dr. Jekyll and Mr. Hyde" of JavaScript. When "this" is used outside of an object, it refers to the global object. But within a method, "this" refers to the object that invokes the method. If you're not careful, you could find yourself playing an unending game of hide and seek with "this".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrong Way:&lt;/strong&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;car&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;speed&lt;/span&gt; &lt;span class="o"&gt;=&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;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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: undefined &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;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Right Way: use arrow function.&lt;/strong&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;car&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;speed&lt;/span&gt; &lt;span class="o"&gt;=&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;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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="nx"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 100 &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;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Existential Crisis: undefined versus null
&lt;/h2&gt;

&lt;p&gt;Ah, the age-old debate. Are you absent (null) or just undefined? While null is an assigned value that means "no value or no object", undefined means a variable has been declared but has not yet been assigned a value. You could say null is philosophical about its emptiness, while undefined is blissfully ignorant.&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;let&lt;/span&gt; &lt;span class="nx"&gt;emptyFridge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// You know it's empty&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myFridge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Where did it go?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Rush Hour: Loading Scripts Before the DOM Party Begins
&lt;/h2&gt;

&lt;p&gt;Don't be that guy who shows up at the party before the host. Loading scripts before the DOM is loaded is like going on stage without your script. The actors (HTML elements) aren't ready for you yet!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrong Way:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"myscript.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- Here be dragons...or maybe just HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Right Way:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- Here be dragons...or maybe just HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"myscript.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Naming Variables: A Tragicomedy
&lt;/h2&gt;

&lt;p&gt;The road to programming hell is paved with badly named variables. Keep in mind: 'x', 'temp', 'stuff' are not real names, they're the scribbles of a deranged coder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrong Way:&lt;/strong&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="kd"&gt;let&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;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// What does 'x' even mean?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Right Way:&lt;/strong&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numberOfApples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Oh, now it makes sense!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Extra Piece of Luggage: Redundant else Statements
&lt;/h2&gt;

&lt;p&gt;It's always tempting to pack that extra pair of socks "just in case". But with else statements, more isn't always merrier. Don't be the coder who packs for a blizzard when it's a sunny day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrong Way:&lt;/strong&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&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;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;else&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;y&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;&lt;strong&gt;Right Way:&lt;/strong&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&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;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="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Deceptive Twins: Assignment and Equality Operators
&lt;/h2&gt;

&lt;p&gt;Assignment operator (=) is the obedient child that sets a value to a variable. Equality operator (==) is the inquisitive one, checking if two values are equal. But watch out for their evil twin (===), who checks equality and datatype! Don't get fooled by their family resemblance.&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;let&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;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Assigns the value 10 to x&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;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Returns true&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;x&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Returns false, different datatypes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enjoy your journey with JavaScript. And remember, we've all tripped over these same stones!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is Strict Mode? Or, "The Day JavaScript Morphed Into My Mother"</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Wed, 07 Jun 2023 22:55:17 +0000</pubDate>
      <link>https://forem.com/codetobug/what-is-strict-mode-or-the-day-javascript-morphed-into-my-mother-g4d</link>
      <guid>https://forem.com/codetobug/what-is-strict-mode-or-the-day-javascript-morphed-into-my-mother-g4d</guid>
      <description>&lt;p&gt;Hey, you remember your mother's "Strict Mode"? Those fond memories of teenage years when she transformed into an unyielding warden, barring you from staying out past midnight or using the family PC for anything other than "educational purposes?" Oh, the joy.&lt;/p&gt;

&lt;p&gt;Well, Strict Mode is an ES5 feature, when JavaScript decide to pay tribute to your Mum, adopting a "Strict Mode" of its own. Quite the trendsetter, isn't it?&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;var&lt;/span&gt; &lt;span class="nx"&gt;lateNight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fun&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try pulling that little line of code and you're instantly teleported back to your teen years, complete with a virtual mom wagging her finger at you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turning On Mom Mode, Err... Strict Mode
&lt;/h2&gt;

&lt;p&gt;Sliding into JavaScript's Strict Mode is as simple as entering your teenage years - just add "use strict"; at the beginning of your script. Yes, those were the magical words that turned your cool, lenient mom into a strict, no-nonsense matriarch.&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;let&lt;/span&gt; &lt;span class="nx"&gt;party&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Joy of Conforming: Benefits of Mom, I Mean... Strict Mode
&lt;/h2&gt;

&lt;p&gt;Strict Mode's benefits are like those brussels sprouts mom forced you to eat. You hated them but they were good for you, right?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prevents Evil Twins:&lt;/strong&gt; Just like mom would never let you hang out with your evil doppelgänger, JavaScript refuses to let you declare identical variables. I mean, come on, who needs two 'Bobs' anyway?&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;let&lt;/span&gt; &lt;span class="nx"&gt;bob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;happy&lt;/span&gt;&lt;span class="dl"&gt;"&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;bob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sad&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Error: Bob already exists!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Blocks Naughty Behavior:&lt;/strong&gt; Just like mom's grounding kept you from sneaking out at night, Strict Mode keeps you from using undeclared variables. Ah, the joys of discipline.&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="nx"&gt;sneakyVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I'm out&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Error: Declare your variables, young person!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mutes Silent Errors:&lt;/strong&gt; Silent errors are like mom's cold shoulder - no noise, but you knew you were in for it. Strict Mode turns these silent errors into loud, screaming tantrums.&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="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;// Error: What were you thinking?!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, folks, that's JavaScript's Strict Mode for you. A relentless taskmaster, sure, but one that's got your best interests at heart. Just like dear ol' mom!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Grid for disorder, Flexbox for chaos</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Wed, 07 Jun 2023 12:45:53 +0000</pubDate>
      <link>https://forem.com/codetobug/grid-for-disorder-flexbox-for-chaos-4l4k</link>
      <guid>https://forem.com/codetobug/grid-for-disorder-flexbox-for-chaos-4l4k</guid>
      <description>&lt;p&gt;Why not complicate life a bit more? In the world of web design, life wouldn't make sense if we didn't complicate it a little. And to make our lives even harder, we have Grid and Flexbox! Both are super modern design tools, but each one has its own quirks that pull our hair out. So here we are to clear your doubts and, by the way, have a little fun!&lt;/p&gt;

&lt;h2&gt;
  
  
  Grid vs Flexbox: Clash of titans you didn't know existed
&lt;/h2&gt;

&lt;p&gt;First, let's talk about the difference between the two, so you feel like an expert at the next designers' meeting. Grid is like a chessboard where you can place your pieces however you want, regardless of whether they can actually move that way. Flexbox, on the other hand, is like an elastic band that stretches and shrinks your elements depending on its mood.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to choose the lesser evil?
&lt;/h2&gt;

&lt;p&gt;Now, if you're at a crossroads of which technology to use, we'll tell you there's no universal answer. But a general rule is: if you want a web design that looks like an abstract painting, use Grid; if you prefer a jumble of elements where nothing makes sense, choose Flexbox.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use cases and examples that will save your life
&lt;/h2&gt;

&lt;p&gt;So that you're not left wondering, here are some examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSS Grid: A maze with no exit&lt;/strong&gt;&lt;br&gt;
Ideal for those moments when you want to create a design with rows and columns, but it appears as if it was made by a conceptual artist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSS Flexbox: When anarchy takes shape&lt;/strong&gt;&lt;br&gt;
Perfect for when you have no idea what you're doing, but you still want your elements to look together and, at the same time, apart.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mixing the unmixable: Grid and Flexbox&lt;/strong&gt;&lt;br&gt;
If they seem boring separately, try mixing them! It will be like combining oil and water, but in your web design. Imagine the endless possibilities of chaos and disorder!&lt;/p&gt;

&lt;h2&gt;
  
  
  When everything goes wrong in both worlds
&lt;/h2&gt;

&lt;p&gt;But if you think this can't get worse, here are some examples of when everything goes wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using CSS Grid for a header: Who needs structure?&lt;/strong&gt;&lt;br&gt;
Why settle for a boring and structured header when you can create one that looks like it was designed by a 5-year-old with CSS Grid?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using CSS Grid for tabs: What could go wrong?&lt;/strong&gt;&lt;br&gt;
Do you want your tabs to look like an impossible puzzle to solve? Use CSS Grid! Nothing better than seeing your visitors struggle to find the information they're looking for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Abusing Grid and Flexbox: The apocalypse in your design&lt;/strong&gt;&lt;br&gt;
Who said less is more? Use Grid and Flexbox everywhere! That way, every time someone sees your website, they'll wonder if they're living in a surreal nightmare.&lt;/p&gt;

&lt;p&gt;Well, now that you know the secrets of Grid and Flexbox, you're ready to embark on the wonderful world of chaos and despair in your web designs. Don't forget to share your masterpieces on social media so everyone can enjoy your amazing and confusing creations. Good luck!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Learn to Cook Up JavaScript Spells: So Easy Even Grandma Can Do It</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Wed, 07 Jun 2023 12:36:48 +0000</pubDate>
      <link>https://forem.com/codetobug/learn-to-cook-up-javascript-spells-so-easy-even-grandma-can-do-it-1pce</link>
      <guid>https://forem.com/codetobug/learn-to-cook-up-javascript-spells-so-easy-even-grandma-can-do-it-1pce</guid>
      <description>&lt;p&gt;Crack your knuckles, aspiring coders! This is your jargon-free, absurdly easy guide to basic JavaScript that's so friendly, even your grandma could ace it (We love you, grandma!).&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Summoning the Spirit of Fibonacci: Making an Array from a Range of Numbers
&lt;/h2&gt;

&lt;p&gt;Here, let’s conjure an array from a set range of numbers because, why not? You know, just like making cookies but without the calories.&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;let&lt;/span&gt; &lt;span class="nx"&gt;arrayFromRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;min&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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. An Existential Dilemma: Odd or Even?
&lt;/h2&gt;

&lt;p&gt;Next, a conundrum that has baffled philosophers for eons - is the number odd or even? Such profound questions, such riveting suspense.&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;let&lt;/span&gt; &lt;span class="nx"&gt;isEven&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Word Surgery: Extracting a Bit of a Text String
&lt;/h2&gt;

&lt;p&gt;Time for a little surgery. Scapel...er, I mean, substring, please! Let’s extract that stubborn bit of text.&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;let&lt;/span&gt; &lt;span class="nx"&gt;extractSubString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Identity Switch Operation: Replacing a Text String
&lt;/h2&gt;

&lt;p&gt;Next, we perform the mystical art of identity change. Who knew text strings could be so flexible?&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;let&lt;/span&gt; &lt;span class="nx"&gt;replaceString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;oldStr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newStr&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldStr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newStr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. The Beginning and End of the World: Checking if a Text String Starts or Ends with Certain Words
&lt;/h2&gt;

&lt;p&gt;Does it start? Does it end? Just like reading an intriguing novel, but with less drama and more determinism.&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;let&lt;/span&gt; &lt;span class="nx"&gt;startsOrEndsWith&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;checkStr&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;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;checkStr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;checkStr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. A Deep Clean: Removing All Empty Spaces from a Text String
&lt;/h2&gt;

&lt;p&gt;Now let’s make that messy string squeaky clean. Sorry, spaces, you’ve overstayed your welcome!&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;let&lt;/span&gt; &lt;span class="nx"&gt;removeSpaces&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;+/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Superhero Strength: Getting the Power of a Number
&lt;/h2&gt;

&lt;p&gt;Get ready to flex your mathematical muscles. Time to find the power of a number.&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;let&lt;/span&gt; &lt;span class="nx"&gt;powerOfNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;power&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;power&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Crystal Ball: Checking if an Object has a Specific Property
&lt;/h2&gt;

&lt;p&gt;Here we peer into the murky depths of an object, divining its properties. It’s less spooky than it sounds, promise!&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;let&lt;/span&gt; &lt;span class="nx"&gt;hasProperty&lt;/span&gt; &lt;span class="o"&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;prop&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;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. A Mysterious Double: Creating a Copy of an Object
&lt;/h2&gt;

&lt;p&gt;Don't want to mess with the original? Make a doppelgänger. It's like having a twin, but with less sibling rivalry.&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;let&lt;/span&gt; &lt;span class="nx"&gt;copyObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;assign&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  10. Magical Vanishing Act: Removing a Property from an Object
&lt;/h2&gt;

&lt;p&gt;Now, for the pièce de résistance, we're going to make a property disappear! Just like magic, but less flashy.&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;let&lt;/span&gt; &lt;span class="nx"&gt;removeProperty&lt;/span&gt; &lt;span class="o"&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;prop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&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;obj&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;h2&gt;
  
  
  11. A World Without Clones: Removing Duplicate Items from an Array
&lt;/h2&gt;

&lt;p&gt;Duplicates are so passé. Let’s spring clean that array!&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;let&lt;/span&gt; &lt;span class="nx"&gt;removeDuplicates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  12. Two-Headed Monster: Merging Two Arrays or Objects
&lt;/h2&gt;

&lt;p&gt;Lastly, the beast of all beasts - merging arrays or objects. Don't worry, no actual monsters were harmed.&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;let&lt;/span&gt; &lt;span class="nx"&gt;mergeItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item1&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;item1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;item2&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;item1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;item2&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voilà! You’ve now dipped your toes into the enchanting world of JavaScript. Remember, practice makes perfect and if your grandma can do it, so can you. Get coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Summoning a Full Stack Developer: Is it One Person or a Tech Army?</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Tue, 06 Jun 2023 16:47:18 +0000</pubDate>
      <link>https://forem.com/codetobug/summoning-a-full-stack-developer-is-it-one-person-or-a-tech-army-5dob</link>
      <guid>https://forem.com/codetobug/summoning-a-full-stack-developer-is-it-one-person-or-a-tech-army-5dob</guid>
      <description>&lt;p&gt;Dear weary recruiters, ever sought after a mythical creature that's part Java guru, part AWS wizard, part Python charmer? Hint: you're shopping for an entire IT department, not a 'Full Stack Developer'.&lt;/p&gt;

&lt;p&gt;Greetings, noble recruiters on the quest for the elusive Full Stack Developer. In this realm of tech wizardry, this term has become somewhat of a modern unicorn - rumored to exist, yet strangely hard to locate. Why, you ask? Buckle up, for I am about to burst your fantasy bubble.&lt;/p&gt;

&lt;p&gt;Firstly, let's talk about Java, Python, PHP. Such languages, so much diversity! You desire a polyglot savant, someone who can, in the dead of night, while possibly cooking a three-course meal, code proficiently in all these languages. That's like expecting one person to pen a novel in English, Spanish, and Mandarin simultaneously. Simple, right?&lt;/p&gt;

&lt;p&gt;Now, let's waltz into the enchanting land of React and Angular. A realm where folks speak only in components and directives. It's a delicate dance, the JavaScript frameworks tango. You're not just asking for someone who can do the steps, but also a choreographer, lighting designer, and costume designer all rolled into one. Dancing with the Stars has nothing on this.&lt;/p&gt;

&lt;p&gt;Onward to the mysterious realm of databases - PostgreSQL, Reds, MongoDB. Here, your Full Stack Developer unicorn needs to navigate the vast terrain of data jungles. Think Indiana Jones in khakis, cracking the whip at poor, unsuspecting SQL queries.&lt;/p&gt;

&lt;p&gt;Then, there’s the ubiquitous AWS with its loyal knights S3, EC2, ECS, EKS. Are we seeking a Full Stack Developer or a full-on cloud god? A deity who can summon thunderous instances and gentle storage buckets from the infinite ether, all while juggling Linux system administration duties. Easy peasy!&lt;/p&gt;

&lt;p&gt;What's this now? You say you also need a champion of Git, CI, TDD, Docker, Kubernetes? That's like asking for a symphony conductor who can play every instrument while simultaneously tuning them, and oh, writing the symphony as well.&lt;/p&gt;

&lt;p&gt;So recruiters, let's clarify. What you seek isn’t a Full Stack Developer, that mystical tech creature, but an entire IT department. Yes, a fully staffed, caffeine-fueled, keyboard-tapping, code-deploying IT department. But, by all means, continue your pursuit for that one-size-fits-all tech guru. We'll grab the popcorn.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>career</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Unleashing the Sorcery of JavaScript Regular Expressions: Now You See Me, Now You Don't!</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Tue, 06 Jun 2023 16:09:10 +0000</pubDate>
      <link>https://forem.com/codetobug/unleashing-the-sorcery-of-javascript-regular-expressions-now-you-see-me-now-you-dont-27kd</link>
      <guid>https://forem.com/codetobug/unleashing-the-sorcery-of-javascript-regular-expressions-now-you-see-me-now-you-dont-27kd</guid>
      <description>&lt;p&gt;Dive into the cryptic world of JavaScript Regular Expressions. Picture yourself as a wizard, casting spells over text strings. Prepare to warp reality—or just data, whatever floats your broomstick.&lt;/p&gt;

&lt;p&gt;So you want to master the mystic arts of JavaScript Regular Expressions, huh? Well, brave sorcerer, strap on your pointy hat, grab your wand, and let's weave magic over unsuspecting strings of text, shall we?&lt;/p&gt;

&lt;p&gt;Let's start with the first spell—sorry, I mean "Regular Expression"—in our grimoire. Want to find a sneaky word hiding within a text, playing a medieval version of Hide 'n Seek? Here's a little incantation that works like a divination charm:&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;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Once upon a midnight dreary, while I pondered, weak and weary&lt;/span&gt;&lt;span class="dl"&gt;"&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;mySpell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/dreary/&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;mySpell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// It's like shouting "Reveal yourself, dreary!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you think it returns? A ghost? No, my dear Merlin, it’s not that complex. It just gives a simple "true" or "false". Boolean values. Not very Hogwarts-y, but that's the mundane life of a JavaScript mage for you.&lt;/p&gt;

&lt;p&gt;Next, let's say you're trying to attract all the numbers in a text. Like a magnet spell for numerals. Yes, you can totally do that. Here's how you enchant a string to reveal all its hidden digits:&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;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I have 7 horcruxes, 3 broomsticks, and 1 very fancy hat.&lt;/span&gt;&lt;span class="dl"&gt;"&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;numberSpell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\d&lt;/span&gt;&lt;span class="sr"&gt;+/g&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;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numberSpell&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Shout, "Numbers, assemble!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, voila! You'll see ["7", "3", "1"]—the numbers, plucked from their cozy textual abode. Magic? More like Regular Expressions. But hey, six of one, half a dozen of the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meta characters
&lt;/h2&gt;

&lt;p&gt;Ah, back to the magical world of Regular Expressions we go! Let's decode the secret ingredients—the meta-characters—that infuse our spells with their unique powers. Remember, a master wizard is not made in a day, so take your time understanding these formula elements.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Dot .
&lt;/h3&gt;

&lt;p&gt;The dot is like the all-purpose eye of a newt. It morphs into any character you need, except a fresh line break. But remember, it can transform just once:&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;let&lt;/span&gt; &lt;span class="nx"&gt;allSeeingDot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/b.t/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// A "bat", "bit", or "but", it matters not!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Caret ^
&lt;/h3&gt;

&lt;p&gt;The caret is the rooster's crow, signaling the break of dawn. It signifies the start of a line:&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;let&lt;/span&gt; &lt;span class="nx"&gt;roostersCrow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/^Alohomora/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Only works if "Alohomora" is the first spell of the day!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Dollar Sign $
&lt;/h3&gt;

&lt;p&gt;Much like the sandman's dust, the dollar sign signifies the end. It's concerned only with the end of a line:&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;let&lt;/span&gt; &lt;span class="nx"&gt;sandmansDust&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/nocturne$/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Only "nocturne" at the end of a lullaby will do.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Star * and Plus +
&lt;/h3&gt;

&lt;p&gt;The star is like your infinite bag of fairy dust, allowing for zero or more characters. The plus is its more demanding sibling; it insists on at least one character:&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;let&lt;/span&gt; &lt;span class="nx"&gt;fairyDust&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/ho*/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Can summon "h", "ho", "hoo", "hooo"... an endless bag indeed.&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;demandingDust&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/ho+/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// But this one needs at least one "o" after "h". More is merrier though!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Question Mark ?
&lt;/h3&gt;

&lt;p&gt;The question mark is akin to the elusive unicorn. It allows for the mythical 'maybe'— zero or one occurrence of the character before it:&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;let&lt;/span&gt; &lt;span class="nx"&gt;elusiveUnicorn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/wiz&lt;/span&gt;&lt;span class="se"&gt;?&lt;/span&gt;&lt;span class="sr"&gt;ard/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Transforms into both "wizard" and "ward". It's a unicorn, after all!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Backslash \
&lt;/h3&gt;

&lt;p&gt;The backslash is the powerful ward of protection. It safeguards special characters, allowing them to be used in their true form:&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;let&lt;/span&gt; &lt;span class="nx"&gt;protectiveWard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="sr"&gt;5/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// No transformation this time, just a good old dollar sign.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. Square Brackets []
&lt;/h3&gt;

&lt;p&gt;The square brackets are like your friendly house elves, working only for specific characters:&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;let&lt;/span&gt; &lt;span class="nx"&gt;faithfulElves&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;abc&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Only "a", "b", and "c" shall pass.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. Parentheses ()
&lt;/h3&gt;

&lt;p&gt;Parentheses are akin to your time turner, capturing a moment (group of characters) to be revisited later:&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;let&lt;/span&gt; &lt;span class="nx"&gt;timeTurner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;expelli&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;armus/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Captures "expelliarmus", but "expelli" is stashed away in the time capsule.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9. Pipe |
&lt;/h3&gt;

&lt;p&gt;The pipe is your potion of choice, denoting 'or'. It chooses the pattern before or after it:&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;let&lt;/span&gt; &lt;span class="nx"&gt;potionOfChoice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/gryffindor|hufflepuff/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Whether you're a lion or a badger, this potion has got your back.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, there you go! Your magical guide to the meta-characters that power the world of Regular Expressions in JavaScript. Use these formula elements wisely, keep weaving your spells, and you'll be conjuring powerful Regular Expressions in no time!&lt;/p&gt;

&lt;p&gt;Ah, wizard of Regex, eager to learn more spells to bend the universe of text to your will, are we? Good! Now, gather round as we conjure further mysteries of Regular Expressions in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Matching an Email Address
&lt;/h2&gt;

&lt;p&gt;Need to pluck out an email address from the chaotic cacophony of characters? Try this magical formula:&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;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You can reach me at gandalf@middleearth.com&lt;/span&gt;&lt;span class="dl"&gt;"&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;emailSpell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\b[&lt;/span&gt;&lt;span class="sr"&gt;A-Za-z0-9._%+-&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+@&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Za-z0-9.-&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;\.[&lt;/span&gt;&lt;span class="sr"&gt;A-Z|a-z&lt;/span&gt;&lt;span class="se"&gt;]{2,}\b&lt;/span&gt;&lt;span class="sr"&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;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;emailSpell&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Shout, "Email, reveal thyself!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it, "&lt;a href="mailto:gandalf@middleearth.com"&gt;gandalf@middleearth.com&lt;/a&gt;" will pop up faster than you can say "You shall not pass"!&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Capturing Text Between Double Quotes
&lt;/h2&gt;

&lt;p&gt;Hidden messages between double quotes, you say? Unravel them with this simple incantation:&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;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;"Speak "friend" and enter." "Mellon"&lt;/span&gt;&lt;span class="dl"&gt;'&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;quoteSpell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/"&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;.*&lt;/span&gt;&lt;span class="se"&gt;?)&lt;/span&gt;&lt;span class="sr"&gt;"/g&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;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;quoteSpell&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// "Secrets in quotes, come forth!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here come "friend" and "Mellon", stepping out from the shadows between the quotes!&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Get Content Inside an HTML Tag
&lt;/h2&gt;

&lt;p&gt;Looking to sneak a peek inside an HTML tag? Here's a spell that does the trick:&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;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;title&amp;gt;One Ring to Rule Them All&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&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;htmlSpell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&amp;lt;title&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;.*&lt;/span&gt;&lt;span class="se"&gt;?)&lt;/span&gt;&lt;span class="sr"&gt;&amp;lt;&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;title&amp;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;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;htmlSpell&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="c1"&gt;// Shout, "Title, unveil thy contents!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just like that, "One Ring to Rule Them All" is revealed, just as it was hidden within the 'title' tags.&lt;/p&gt;

&lt;p&gt;And remember, dear wizard, with great Regular Expression power comes great text-manipulating responsibility. Use your newfound powers wisely!&lt;/p&gt;

&lt;p&gt;So there you have it, aspiring Regular Expressions sorcerers. We've scratched the surface of our mystical, text-manipulating adventure. It's a ride that's as unpredictable as a potion mixing class, and just as fun. One thing's for sure, though, the more you dive into JavaScript Regular Expressions, the less 'regular' they seem. So, keep practicing your spells, keep honing your craft, and soon enough, you'll be the Dumbledore of JavaScript Regular Expressions!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Adding a Soldier to Your JavaScript Array Army: A Tactical Guide to High-Intensity Programming</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Tue, 06 Jun 2023 13:29:10 +0000</pubDate>
      <link>https://forem.com/codetobug/adding-a-soldier-to-your-javascript-array-army-a-tactical-guide-to-high-intensity-programming-2n40</link>
      <guid>https://forem.com/codetobug/adding-a-soldier-to-your-javascript-array-army-a-tactical-guide-to-high-intensity-programming-2n40</guid>
      <description>&lt;p&gt;Attention all code generals! We're heading to the battlefront of JavaScript arrays. Our mission? Add a soldier at a precise index. It's easy, they said. Well, "easy" is relative. Brace yourselves!&lt;/p&gt;

&lt;p&gt;Imagine you're leading an army. Not just any army, but an army of integers, strings, objects, and yes, undefined soldiers (we don't talk about them much). Your JavaScript array army is lined up, ready for battle against the dark forces of... your code project.&lt;/p&gt;

&lt;p&gt;Now, you've just got a new recruit and you're thinking, where should I place them in my neat little formation? Well, isn't it obvious? Wherever you want!&lt;/p&gt;

&lt;p&gt;The JavaScript army is the epitome of inclusivity and chaos. You can place this new soldier in the front, back, middle, wherever. But not just anywhere! This isn't a casual game of poker, but high-intensity coding combat. Let me guide you through this tactical conundrum using our beloved .splice() method.&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;let&lt;/span&gt; &lt;span class="nx"&gt;army&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;Pvt. Zeros&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;Cpl. Ones&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;Sgt. Twos&lt;/span&gt;&lt;span class="dl"&gt;'&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;recruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Gen. Threes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Insert Gen. Threes at index 2. The power move.&lt;/span&gt;
&lt;span class="nx"&gt;army&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="mi"&gt;2&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;recruit&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;army&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ['Pvt. Zeros', 'Cpl. Ones', 'Gen. Threes', 'Sgt. Twos']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at that! You've just stuck Gen. Threes between Cpl. Ones and Sgt. Twos. Now that's what I call a strategic surprise!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But wait, you say, what does &lt;strong&gt;splice(2, 0, recruit)&lt;/strong&gt; mean? Well, my dear coding strategist, the first parameter is the index to add the recruit, the second is the number of soldiers to be removed (none, in this case), and the third is our brave recruit.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, remember, in the chaotic battlefield of your codebase, you don't just have power, you have the power to confuse your enemies with the unexpected positioning of your troops. After all, the war of code is a game of minds and arrays! And remember, in JavaScript, there's no such thing as too many soldiers! Unless you run out of memory, of course. But hey, that's a battle for another day.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Spin Around the JavaScript Merry-Go-Round: Your Daily Routine Reimagined!</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Tue, 06 Jun 2023 13:23:04 +0000</pubDate>
      <link>https://forem.com/codetobug/a-spin-around-the-javascript-merry-go-round-your-daily-routine-reimagined-55d9</link>
      <guid>https://forem.com/codetobug/a-spin-around-the-javascript-merry-go-round-your-daily-routine-reimagined-55d9</guid>
      <description>&lt;p&gt;Oh, the sweet irony of life! The cosmic joke that is existence has a parallel in our digital realm - the thrilling world of JavaScript loops. Imagine, if you will, the joyous monotony of your daily routine. The routine, much like our dear friend the JavaScript loop, hums the anthem of redundancy, providing a beautifully predictable backdrop to our chaotic lives.&lt;/p&gt;

&lt;p&gt;Ah, the loops - &lt;strong&gt;'for', 'forEach', 'do...while', 'while', 'for...in', 'for...of'&lt;/strong&gt;. Each with their quirks, their eccentricities. Their individual characters shine through their wonderfully circular logic. Much like us, each with our own idiosyncratic morning rituals, lunch habits, and bedtime routines, these loops help render the complex fabric of our code into something almost poetically mundane.&lt;/p&gt;

&lt;p&gt;Welcome to the magical carousel of JavaScript loops, where the dance of repetition never ends, where the jesters of routine code your day into existence. Buckle up and get ready for this joyride!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The 'for' Loop: The Toothbrush of JavaScript
&lt;/h2&gt;

&lt;p&gt;Everyone loves a routine, right? Much like your diligent habit of brushing your teeth twice a day, the 'for' loop is all about that rinse and repeat life. Let's consider this simple, yet riveting 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="k"&gt;for&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;i&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&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="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;Brush teeth&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;Twice a day, every day - this 'for' loop will ensure your code's teeth remain sparkling. As thrilling as watching toothpaste foam!&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The 'forEach' Loop: The Breakfast Club
&lt;/h2&gt;

&lt;p&gt;Have you ever sat down to a bowl of cereal and wished that every individual flake had its own spoonful of milk? Well, that's the beauty of the 'forEach' loop. It makes sure every element in your array is served with a side of 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;let&lt;/span&gt; &lt;span class="nx"&gt;breakfast&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;cereal&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;milk&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;fruit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;breakfast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;`Eat &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="s2"&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;A 'forEach' for each item in your breakfast - what a nourishing start to your coding day!&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The 'do...while' Loop: A Workaholic's Mantra
&lt;/h3&gt;

&lt;p&gt;You're the type to start a task before even checking if it's the weekend, aren't you? Well, the 'do...while' loop is your spirit animal. Or should we say, spirit 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;let&lt;/span&gt; &lt;span class="nx"&gt;day&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;do&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;Work&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getDay&lt;/span&gt;&lt;span class="p"&gt;();&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;day&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It'll keep grinding, just like you, tirelessly checking if it's time to stop. If only we could automate our work life as effortlessly!&lt;/p&gt;

&lt;h3&gt;
  
  
  4. The 'while' Loop: The Eternal Optimist
&lt;/h3&gt;

&lt;p&gt;'While' loops are the eternally hopeful optimists of JavaScript. Stuck in traffic during rush hour? This loop will keep running, just like your futile hope for a clear road ahead.&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;let&lt;/span&gt; &lt;span class="nx"&gt;traffic&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="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;traffic&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;Wait in traffic&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;traffic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;checkTraffic&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;Isn't that a beautifully optimistic loop? Let's just hope that traffic check function works faster than your road rage.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The 'for...in' Loop: The Nostalgic Marauder
&lt;/h2&gt;

&lt;p&gt;Ever taken a trip down memory lane, looking at old photos, reminiscing about the past? The 'for...in' loop does the same, just with object properties. It saunters through each, making sure no property goes unnoticed.&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;let&lt;/span&gt; &lt;span class="nx"&gt;dailyRoutine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;breakfast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;oatmeal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;work&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;coding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dinner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pasta&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;dailyRoutine&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="s2"&gt;`Do &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;task&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's like a walk through your past daily routine, a nostalgic reminder of a day well spent. Or coded.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. The 'for...of' Loop: The Hipster of Loops
&lt;/h2&gt;

&lt;p&gt;'for...of' is like the hipster of JavaScript loops. It doesn't care about properties, it's all about the values. Like following a band no one's heard of... yet.&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;let&lt;/span&gt; &lt;span class="nx"&gt;playlist&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;pop&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;rock&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;jazz&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;genre&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;playlist&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="s2"&gt;`Listen to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;genre&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'for...of' is all about appreciating the underappreciated values. A code loop that's a little too cool for school.&lt;/p&gt;

&lt;h3&gt;
  
  
  The 'for...in' vs 'for...of' Drama: A Soap Opera of Loops
&lt;/h3&gt;

&lt;p&gt;The tension between 'for...in' and 'for...of' could power a daytime soap opera. Which will win the coveted title of your favorite loop?&lt;/p&gt;

&lt;p&gt;To choose between 'for...in' (our memory lane marauder) and 'for...of' (our hipster pal) is like choosing between brushing your teeth before or after breakfast. Does it matter? Probably. Do we care? Probably not. As long as the job gets done and our code runs, we're all winners here.&lt;/p&gt;

&lt;p&gt;There you have it. The riveting world of JavaScript loops, as exciting as your everyday routine. Now, go forth and code your daily life into an endless loop of fun and laughter!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Sweeter Promises: The Love Affair of JavaScript Promises.</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Mon, 05 Jun 2023 16:32:21 +0000</pubDate>
      <link>https://forem.com/codetobug/sweeter-promises-the-love-affair-of-javascript-promises-c63</link>
      <guid>https://forem.com/codetobug/sweeter-promises-the-love-affair-of-javascript-promises-c63</guid>
      <description>&lt;p&gt;In the enthralling world of JavaScript, Promises are like your typical romantic rendezvous. They can keep you waiting, surprise you with joy, or leave you heartbroken. Let's dive into this digital dating drama!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Beguiling Charms of Promises in JavaScript
&lt;/h2&gt;

&lt;p&gt;Ah, love! So elusive, so complex, just like our dear JavaScript Promises. Promises, in JavaScript, are like the language's way of dealing with asynchronous operations, acting somewhat like suitors in a dating game. They "promise" to come back with results, but like any star-crossed lover, they might succeed, fail, or keep you hanging.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Endearing Lifecycle of Promises
&lt;/h2&gt;

&lt;p&gt;A Promise in JavaScript, just like a romantic entanglement, goes through a whirlwind of stages:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The "Pending" Courtship
&lt;/h3&gt;

&lt;p&gt;In the world of Promises, a "pending" Promise is like a lover who's asked you out but hasn't shown up yet. You wait, heart fluttering, hoping for the best. Just like 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;let&lt;/span&gt; &lt;span class="nx"&gt;ourDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&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;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&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're pending here. Let's hope ourDate shows up!&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. The "Fulfilled" Union
&lt;/h3&gt;

&lt;p&gt;Ah! The joy when your date finally arrives, the Promise is "fulfilled". It's like:&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;ourDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&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;result&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;Our date is here!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Fulfilled!&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. The "Rejected" Heartbreak
&lt;/h3&gt;

&lt;p&gt;But alas, not all Promises are meant to be! Sometimes, they stand you up, they fail. They're "rejected". It feels something like:&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;ourDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&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;error&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;Our date didn't show up...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Rejected!&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stringing Along with Chained Promises
&lt;/h2&gt;

&lt;p&gt;Oh, the drama doesn't end there! Our JavaScript Promises can keep you on a string, making you hope for one Promise after another, just like a string of dates!&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;firstDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&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="nx"&gt;secondDate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;then&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="nx"&gt;thirdDate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&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="s2"&gt;Well, one of them didn't show up...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Someone broke the chain!&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Flirting Tools for Promises: Helpful Functions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Promise.all() – The Group Date
&lt;/h3&gt;

&lt;p&gt;When you just can't decide and want to see all your prospects together, there's Promise.all(). It waits until all the Promises have shown up (or until one of them fails, the party pooper!).&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="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;date1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;date2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;date3&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nx"&gt;then&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;values&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;All my dates are here!&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;catch&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="s2"&gt;One of them didn't show up...&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;h3&gt;
  
  
  2. Promise.race() – The Speed Date
&lt;/h3&gt;

&lt;p&gt;If you're impatient and just want the first date to show up, use Promise.race(). It's the speed dating of the JavaScript world!&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="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;race&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;date1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;date2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;date3&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nx"&gt;then&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;values&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;One of my dates is here!&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;catch&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="s2"&gt;Well, none of them showed up in time...&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;h3&gt;
  
  
  3. Promise.resolve() and Promise.reject() – The Matchmaker
&lt;/h3&gt;

&lt;p&gt;And for the times when you know the outcome, there's Promise.resolve() and Promise.reject(). They're like the matchmakers of the JavaScript dating world, deciding the fate of your Promise.&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;let&lt;/span&gt; &lt;span class="nx"&gt;successfulDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Our date is a success!&lt;/span&gt;&lt;span class="dl"&gt;"&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;failedDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Our date didn't show up...&lt;/span&gt;&lt;span class="dl"&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 JavaScript dating game, Promises might be a whirlwind of emotions, but remember, it's all part of the exhilarating ride. Here's to hoping for more fulfilled Promises and less heartbreaks!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Authentication for Dummies: Because Your Cat Could Probably Do It Better</title>
      <dc:creator>codeToBug</dc:creator>
      <pubDate>Wed, 31 May 2023 19:20:05 +0000</pubDate>
      <link>https://forem.com/codetobug/react-authentication-for-dummies-because-your-cat-could-probably-do-it-better-4hkf</link>
      <guid>https://forem.com/codetobug/react-authentication-for-dummies-because-your-cat-could-probably-do-it-better-4hkf</guid>
      <description>&lt;p&gt;You know what’s harder than splitting the atom? React authentication. It's like putting your cat in charge of your diet. Not impossible, just...you know, 'fun.&lt;/p&gt;

&lt;p&gt;So, you've decided to embark on the high seas of React authentication? Good for you! You have chosen a journey that is akin to teaching a goldfish how to perform a moonwalk. This task, dear reader, is just as simple as learning ancient Sanskrit during your lunch break.&lt;/p&gt;

&lt;p&gt;First things first. You want to set up your environment. It's like making a soufflé, really. Just grab some Node.js, npm, your text editor and a whole bucket of courage. Or, you know, just download the Internet - same thing.&lt;/p&gt;

&lt;p&gt;Now, on to React. You install it by typing 'npm install react'. This is the part where your computer gets a PhD in modern art. Feel free to reward it with a fresh cup of virtual coffee.&lt;/p&gt;

&lt;p&gt;But oh, what’s this? You need a back end too? Just when you thought it was all rainbows and unicorns. Well, you don't want the mischievous gremlins from the internet to get your user data, do you? So, we add Express.js to our tech smoothie.&lt;/p&gt;

&lt;p&gt;I mean, it's just like ordering a coffee, right? Except you're not actually ordering a coffee. You're summoning a mighty arcane dragon from the abyss. Express.js sounds better, though. Trust me, your therapist will thank me.&lt;/p&gt;

&lt;p&gt;Next, you’ll need an authentication service. Let's pick JWT because, hey, why not? It's an elegant solution if your definition of elegance involves juggling live jellyfish.&lt;/p&gt;

&lt;p&gt;Now let's mix it all together in a blender and hit puree. Boom! You've got yourself a simple React authentication system. You're practically a wizard now.&lt;/p&gt;

&lt;p&gt;There you have it, folks. React authentication, the equivalent of getting your pug to perform the opera. May your debugging sessions be few and your login buttons never prompt for the wrong password. Go forth, brave adventurer, into the wild world of React. After all, who needs sanity when you have JavaScript?&lt;/p&gt;

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