<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Elise Marie LaBonte</title>
    <description>The latest articles on DEV Community by Elise Marie LaBonte (@eliselabonte).</description>
    <link>https://dev.to/eliselabonte</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%2F809414%2F2f4c595a-9318-4c62-a02c-eff83defb560.jpeg</url>
      <title>DEV Community: Elise Marie LaBonte</title>
      <link>https://dev.to/eliselabonte</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eliselabonte"/>
    <language>en</language>
    <item>
      <title>A Controversial Case for Double Equality</title>
      <dc:creator>Elise Marie LaBonte</dc:creator>
      <pubDate>Thu, 10 Feb 2022 21:59:47 +0000</pubDate>
      <link>https://dev.to/eliselabonte/a-controversial-case-for-double-equality-5fnn</link>
      <guid>https://dev.to/eliselabonte/a-controversial-case-for-double-equality-5fnn</guid>
      <description>&lt;p&gt;Maybe this is a common experience in web dev bootcamps.&lt;br&gt;
You're stuck in lecture, trying to stay present while a fire hose of information is blasted at you. You've missed the last six things the instructor has said and then you catch the one thing that's seemed simple this whole time: "Just use triple equality every time. Double equality will inevitably cause bugs".&lt;br&gt;
Man, it's refreshing to have strict rules that I don't need to understand.&lt;/p&gt;

&lt;p&gt;I've been using triple equality in my code ever since. It can be a beautiful thing to behold. So demanding. So pushy. Just look at it.&lt;br&gt;
&lt;code&gt;console.log(12+14===37-11) ** &amp;gt;&amp;gt; true **&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I will admit at the same time that this feels intellectually lazy. And when things feel intellectually lazy, it's usually an omen that relevant bugs will turn their ugly head when you're least expecting.&lt;/p&gt;

&lt;p&gt;The distinction that I always hear between abstract (aka "double") and strict (aka "triple") equality in JS is that triple equality checks the data type while double equality does not, thus making triple equality more useful. &lt;br&gt;
It turns out that that is not accurate. &lt;/p&gt;

&lt;p&gt;below is how each comparison process takes place according to the JS spec.&lt;/p&gt;

&lt;p&gt;abstract/double equality:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ol17dripcnaiai3edya.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ol17dripcnaiai3edya.png" alt="double equality chain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;strict/triple equality:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcmzro44plk1de8hb8wps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcmzro44plk1de8hb8wps.png" alt="triple equality chain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the &lt;em&gt;very first step&lt;/em&gt; for both processes is to check types. The distinction between the two is that strict equality immediately returns false if the types do not match, whereas abstract equality continues comparisons by performing a series of coercions on the data.&lt;/p&gt;

&lt;p&gt;in effect:&lt;br&gt;
&lt;code&gt;var twentySIX = "26"&lt;br&gt;
console.log(26 == twentySix)&lt;/code&gt;&lt;br&gt;
the above code (using abstract equality) would return true, whereas&lt;br&gt;
&lt;code&gt;var twentySIX = "26"&lt;br&gt;
console.log(26 === twentySix)&lt;/code&gt;&lt;br&gt;
the above code (using strict equality) would return false.&lt;/p&gt;

&lt;p&gt;Why does this really matter? &lt;br&gt;
Using strict equality essentially implies that the author does not know (or does not care) what types of data are being passed in... &lt;/p&gt;

&lt;p&gt;But shouldn't we care?&lt;/p&gt;

&lt;p&gt;Kyle Simpson, author of &lt;a href="https://github.com/getify/You-Dont-Know-JS" rel="noopener noreferrer"&gt;You Don't Know JS: Scope &amp;amp; Closures&lt;/a&gt; has a ten hour &lt;a href="https://frontendmasters.com/courses/deep-javascript-v3" rel="noopener noreferrer"&gt;course on Javascript Deep Foundations &lt;/a&gt;that covers this subject where he argues that Javascript authors should very much care about it. Furthermore, he argues that the default should never be to use strict equality. &lt;/p&gt;

&lt;p&gt;While I highly recommend watching his course, here is the spark notes argument:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;the number of cases where abstract equality and strict equality differ are few enough in kind that they should be considered corner cases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;abstract/double equality &lt;em&gt;communicates&lt;/em&gt; to future readers that you, as the author, are confident in the data types being passed in.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;code that knows exactly the types being passed into it is always, as a rule, better code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;not&lt;/em&gt; knowing types means not being confident in your code. when put that way, it is clear that this should be a rarity, not the default mindset.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;==&lt;/code&gt; is more readable than &lt;code&gt;===&lt;/code&gt;, therefore making the code overall more readable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With all of that said, when should strict equality be used?&lt;br&gt;
Again, here is what Kyle Simpson has to say on that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;before the triple equal is to be used, the author should first attempt to refactor their code in a way that they can be confident about types.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;not knowing types is equivalent to assuming type conversion/coercion is happening, in which case you must be defensive in your code, thus necessitating strict equality.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The differences between strict and abstract equality can seem minute when writing code, and the case for defaulting to abstract is certainly not a popular one. Will hobby projects and simpler applications suffer over this? &lt;br&gt;
Probably not.&lt;/p&gt;

&lt;p&gt;However, professionally written code and bug-free apps are goals that we should all have as code writers. It's the mindset of a curious developer to thoroughly understand and have educated opinions on the methods and mechanics of your code. And as dull as reading the spec can be, it's good practice to check how your mental model of your code shapes up against what really happens under-the-hood when it executes.&lt;/p&gt;

&lt;p&gt;Whether you agree with Kyle Simpson's stance on strict-versus-abstract equality or not, it's absolutely worth while to watch his courses. Watching long-time industry professionals discuss their approach (especially when it's controversial) is a great way to discover blind-spots in our own knowledge base.&lt;/p&gt;

&lt;p&gt;check out the JS spec &lt;a href="https://262.ecma-international.org/5.1/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
check out Kyle Simpson's course list on Front End Masters &lt;a href="https://frontendmasters.com/teachers/kyle-simpson/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Cracking into Regex</title>
      <dc:creator>Elise Marie LaBonte</dc:creator>
      <pubDate>Fri, 04 Feb 2022 17:58:09 +0000</pubDate>
      <link>https://dev.to/eliselabonte/cracking-into-regex-fah</link>
      <guid>https://dev.to/eliselabonte/cracking-into-regex-fah</guid>
      <description>&lt;p&gt;Regex (regular expressions) are snippets of code used to search for specific characters. In this tutorial, we'll explore how to write regex using an example I've written which passes latitude and but &lt;em&gt;not&lt;/em&gt; longitude.&lt;/p&gt;

&lt;p&gt;Regex is one of those topics that makes my eyes glaze over as soon as I look at the docs, but I can also say that there are few things more satisfying than having a successfully written block of regex. Not only can it shorten the amount of JS that you write in your functions, there are just some things that &lt;em&gt;can't&lt;/em&gt; be done without it.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Below is a regex which will pass latitude written in a variety of different formats, but which will not pass longitude. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/(?&amp;lt;coordinates&amp;gt;\d{2}[d°\.\-]\s?\d{2}[m'\.\-]\s?\d{2}[s\"\.\- ]\s?)(?&amp;lt;hemisphere&amp;gt;(north)|(south)|(n|s))$/i&lt;/code&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Here is a break down of this regex.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;coordinates&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;hemisphere&amp;gt;&lt;/code&gt; both mark the "names" of their respective blocks within the regex. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
The first group, named 'coordinates' matches two digits, directly followed by a specified symbol, followed by a whitespace, followed by the same pattern repeated twice. The only difference between each repetition of this pattern is that the symbol following the digits can be a D in the first (degrees), an M in the second (minutes), and a S in the third (seconds). The second group, named 'hemisphere' matches different options that signify the southern or northern hemisphere.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Navigate through the table of contents to read an explanation of each piece of this regex.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Anchors&lt;/li&gt;
&lt;li&gt;Quantifiers&lt;/li&gt;
&lt;li&gt;Grouping Constructs&lt;/li&gt;
&lt;li&gt;Bracket Expressions&lt;/li&gt;
&lt;li&gt;Character Classes&lt;/li&gt;
&lt;li&gt;The OR Operator&lt;/li&gt;
&lt;li&gt;Flags&lt;/li&gt;
&lt;li&gt;Character Escapes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Regex Components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Anchors
&lt;/h3&gt;

&lt;p&gt;Anchors specify where the engine searches. They are special characters that do not match any characters being searched. A &lt;code&gt;^&lt;/code&gt; is used just before a character/group to specify that it comes at the beginning of an expression, while a &lt;code&gt;$&lt;/code&gt; is used directly following a character/group to specify that it comes at the end of an expression.&lt;/p&gt;

&lt;p&gt;In our example code, the &lt;code&gt;\$&lt;/code&gt; at the very end means that our coordinate must end in one of the following options: n, N, s, S, 'north', 'south', 'North', 'South'. &lt;br&gt;
ex.&lt;br&gt;
&lt;code&gt;((north)|(south)|(n|s))$&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This ensures two parameters: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a coordinate which does not specify a hemisphere will not match.&lt;/li&gt;
&lt;li&gt;a coordinate which ends in an "east/west" (i.e. longitude) signifying hemisphere will not match.

### Quantifiers
Quantifiers describe how may of a certain character to search for in a group. The following symbols are used as quantifiers: * (search for zero or more occurrences), + (search for one or more occurrences), ? (search for zero or one occurrence), {n} (search for n number of occurrences), {n, z} (search for occurrences numbering between n and z).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In our example, we used quantifiers to specify the number of digits at the degree, minute, and second position in the latitude. (This also aids us in ruling out some longitude inputs, since longitude is often expressed with a three-digit degree.)&lt;br&gt;
ex.&lt;br&gt;
&lt;code&gt;\d{2}&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Grouping Constructs
&lt;/h3&gt;

&lt;p&gt;Items that match a search can be grouped and named. Parentheses help us with this. A name is not necessary for a group, but it can be specified by using the following syntax: (?abc). If no name is specified, the groups will be named numerically by default. &lt;/p&gt;

&lt;p&gt;In our example code, the first group is named 'coordinates' while the second is named 'hemisphere'.&lt;br&gt;
ex.&lt;br&gt;
&lt;code&gt;(?\&amp;lt;coordinates\&amp;gt;.....)&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;(?\&amp;lt;hemisphere\&amp;gt;.....)&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bracket Expressions
&lt;/h3&gt;

&lt;p&gt;Bracket expressions treat the items inside as individual characters. The engine matches any individual character within the brackets. So, a search of [fc]at would match the words fat and cat, but not sat.&lt;/p&gt;

&lt;p&gt;In our example code, we use brackets to match some of the different characters that are used to express longitude, as well as some of the different ways that a north/south hemisphere can be expressed.&lt;br&gt;&lt;br&gt;
ex.&lt;br&gt;
&lt;code&gt;[dD°\.\-\s]&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Character Classes
&lt;/h3&gt;

&lt;p&gt;Character classes are indicated using a bracket expression. They can specify a single character or a range of characters. For example, [a-j] would match any letters between a and j in the alphabet, and [2-7] would match any digits between 2 and 7.&lt;/p&gt;

&lt;h3&gt;
  
  
  The OR Operator
&lt;/h3&gt;

&lt;p&gt;A '|' can be used to match expressions on either side within a set of parentheses. A single character or multiple can be compared here.&lt;/p&gt;

&lt;p&gt;In our example code, we use the OR Operator to specify a hemisphere from a few different options.&lt;br&gt;
ex.&lt;br&gt;
&lt;code&gt;(north)|(south)|(n|s))&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flags
&lt;/h3&gt;

&lt;p&gt;Flags are used at the end of a regex to specify search options. The syntax for flags is a '/' followed by one of the following options: g (global), m (multi-line), u (unicode), (to name a few).&lt;/p&gt;

&lt;p&gt;In our example code, we use a /i at the very end of our regex which allows for a case-sensitive search.&lt;br&gt;
ex.&lt;br&gt;
&lt;code&gt;(north)|(south)|(n|s))$/i&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Character Escapes
&lt;/h3&gt;

&lt;p&gt;When a character must be used which has a functional meaning within a regex, we can use a character escape. These are represented by a '\' or backslash. It is important to note that a '\' specifies a character escape, while a '/' or slash specifies the end of a regex. &lt;/p&gt;

&lt;p&gt;In our example code, we use character escapes to specify both digits (\d) and white space (\s).&lt;br&gt;
ex.&lt;br&gt;
&lt;code&gt;\d{2}&lt;/code&gt;&lt;br&gt;
&lt;code&gt;[mM'\.\-]\s?&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Author
&lt;/h2&gt;

&lt;p&gt;Elise LaBonte is a developer based in Weymouth, Massachusetts. She has been coding since 2020.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/eliselabonte"&gt;https://github.com/eliselabonte&lt;/a&gt;&lt;/p&gt;

</description>
      <category>regex</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
