<?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: Elisa McDonald</title>
    <description>The latest articles on DEV Community by Elisa McDonald (@elisalmcdonald).</description>
    <link>https://dev.to/elisalmcdonald</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%2F1069611%2Fcfa6c773-7ecc-4fb9-9bb4-ea205cc1249c.jpeg</url>
      <title>DEV Community: Elisa McDonald</title>
      <link>https://dev.to/elisalmcdonald</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/elisalmcdonald"/>
    <language>en</language>
    <item>
      <title>Operators in JavaScript!</title>
      <dc:creator>Elisa McDonald</dc:creator>
      <pubDate>Thu, 04 May 2023 19:06:36 +0000</pubDate>
      <link>https://dev.to/elisalmcdonald/operators-in-javascript-5ggm</link>
      <guid>https://dev.to/elisalmcdonald/operators-in-javascript-5ggm</guid>
      <description>&lt;h2&gt;
  
  
  What are Operators?
&lt;/h2&gt;

&lt;p&gt;Operators are special symbols that act on data. They're used to perform operations on values or variables by assigning them to a variable, comparing them, or using them in arithmetic operations.&lt;/p&gt;




&lt;h2&gt;
  
  
  Arithmetic Operators:
&lt;/h2&gt;

&lt;p&gt;Arithmetic operators are used to perform arithmetic on values (either literal or variables). &lt;/p&gt;

&lt;p&gt;&lt;code&gt;+&lt;/code&gt; addition &lt;br&gt;
&lt;code&gt;-&lt;/code&gt; subtraction &lt;br&gt;
&lt;code&gt;*&lt;/code&gt; multiplication&lt;br&gt;
&lt;code&gt;**&lt;/code&gt; exponentiation&lt;br&gt;
&lt;code&gt;/&lt;/code&gt; division&lt;br&gt;
&lt;code&gt;%&lt;/code&gt; modulus aka remainder&lt;br&gt;
&lt;code&gt;++&lt;/code&gt; increment&lt;br&gt;
&lt;code&gt;--&lt;/code&gt; decrement &lt;/p&gt;

&lt;p&gt;Examples of arithmetic operators being used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 + 1 = 2
2 - 1 = 1
2 * 2 = 4
3 ** 2 = 9
4 / 2 = 2
5 % 2 = 1
5++ = 6
5-- = 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Assignment Operators:
&lt;/h2&gt;

&lt;p&gt;Assignment operators assign a value to a variable.&lt;/p&gt;

&lt;p&gt;Examples of assignment operators being used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 2
x += 2 // reassigns x to whatever it was + 2
x -= 2 // reassigns x to whatever it was - 2
x *= 2
x /= 2
x %= 2
x **= 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Comparison Operators:
&lt;/h2&gt;

&lt;p&gt;Comparison operators compare two values to determine equality or difference and evaluate to a boolean aka true or false.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;==&lt;/code&gt; loosely equal to&lt;br&gt;
&lt;code&gt;===&lt;/code&gt; strictly equal to&lt;br&gt;&lt;br&gt;
&lt;code&gt;!=&lt;/code&gt; loosely not equal to&lt;br&gt;
&lt;code&gt;!==&lt;/code&gt; strictly not equal to  &lt;/p&gt;

&lt;p&gt;The difference between loosely equal / not equal &amp;amp; strictly equal to:&lt;br&gt;
Loosely checks if just value are equal.&lt;br&gt;
Strictly checks if &lt;u&gt;&lt;strong&gt;both&lt;/strong&gt;&lt;/u&gt; the value and data type are equal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Helpful Tip:&lt;/strong&gt; Don't use non-strict comparison unless there's a good reason to which is almost never! &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt;&lt;/code&gt; greater than&lt;br&gt;
&lt;code&gt;&amp;lt;&lt;/code&gt; less than&lt;br&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt; greater than or equal to&lt;br&gt;
&lt;code&gt;&amp;lt;=&lt;/code&gt; less than or equal to&lt;/p&gt;

&lt;p&gt;Examples of comparison operators being used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 10

x == 5 // returns true
x == '5' // returns true

x === 5 // returns true
x === '5' // returns false

y != 10 // returns false
y != '10' // returns false

y !== 10 // returns false
y !== '10' // returns true

x &amp;gt; 10 // returns false
x &amp;lt; 10 // returns true

y &amp;gt;= 10 // returns true
y &amp;lt;= 10 // returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Logical Operators:
&lt;/h2&gt;

&lt;p&gt;Logical operators compare two variables or values and determine the logic whether it's true or false&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and&lt;br&gt;
&lt;code&gt;||&lt;/code&gt; or&lt;br&gt;
&lt;code&gt;!&lt;/code&gt; not&lt;/p&gt;

&lt;p&gt;Examples of logical operators being used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 2 
y = 6

// if all inequalities are true it returns true
x &amp;lt; y &amp;amp;&amp;amp; y &amp;gt; 8

// if at least one of the inequalities are true it returns true
x &amp;gt; y || y &amp;lt; 4

// logical opposite
!x === 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Ternary Operators:
&lt;/h2&gt;

&lt;p&gt;The only operator that takes 3 operands: a condition followed by a &lt;code&gt;?&lt;/code&gt; then an expression to execute if the condition is truthy followed by a &lt;code&gt;:&lt;/code&gt; and then the expression to execute if the condition is falsy. The ternary operator is an alternative to using an if else statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let number = 99;

let lessThan100 = number &amp;lt; 100 ? "Less than 100!" : "Sorry your number is not under 100."

console.log(lessThan100); // "Less than 100!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Operators are important tools in JavaScript for performing various operations on data. Each type of operator serves a specific purpose. Understanding how to use operators can help write more efficient and readable code.&lt;/p&gt;

&lt;p&gt;Happy coding! :)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
