<?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: thatgirlvictoria</title>
    <description>The latest articles on Forem by thatgirlvictoria (@thatgirlvictoria).</description>
    <link>https://forem.com/thatgirlvictoria</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%2F803424%2F49068fc1-8f8e-4180-9dbf-fd9e6534063e.jpeg</url>
      <title>Forem: thatgirlvictoria</title>
      <link>https://forem.com/thatgirlvictoria</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/thatgirlvictoria"/>
    <language>en</language>
    <item>
      <title>JavaScript: Unary Operators</title>
      <dc:creator>thatgirlvictoria</dc:creator>
      <pubDate>Wed, 01 Jun 2022 21:57:20 +0000</pubDate>
      <link>https://forem.com/thatgirlvictoria/javascript-unary-operators-43dk</link>
      <guid>https://forem.com/thatgirlvictoria/javascript-unary-operators-43dk</guid>
      <description>&lt;p&gt;This is what I learned about unary operators while working on a 8kyu Codewars challenge in further detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Unary Operators in JavaScript?
&lt;/h2&gt;

&lt;p&gt;To better understand what unary operators are I took apart the word Uni which equals One while operators are a character that represents an action.&lt;/p&gt;

&lt;p&gt;Unary operators work on one value. Below is a table to better explain:&lt;/p&gt;

&lt;p&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%2Fns0z21z0vdn75qet3anc.jpg" 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%2Fns0z21z0vdn75qet3anc.jpg" alt="table of unary operators"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What does this table mean exactly?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Non-numeric values:&lt;/strong&gt; all unary operators will first convert them into a number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unary plus (+)&lt;/strong&gt; when placed before a numeric value, it does nothing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unary minus (-)&lt;/strong&gt; when placed before a numeric value, it will negate it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prefix increment operator&lt;/strong&gt; (++ before value) adds one to a value. Value is changed &lt;strong&gt;before&lt;/strong&gt; the statement is evaluated. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Postfix decrement operator&lt;/strong&gt; (-- before value) minus one to a value. Value is changed &lt;strong&gt;before&lt;/strong&gt; the statement is evaluated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Postfix increment operator&lt;/strong&gt; (++ before value) adds one to a value. Value is changed &lt;strong&gt;after&lt;/strong&gt; the statement is evaluated. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prefix decrement operator&lt;/strong&gt; (-- before value) minus one to a value. Value is changed &lt;strong&gt;after&lt;/strong&gt; the statement is evaluated.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Codewars Challenge: Opposite Number
&lt;/h2&gt;

&lt;p&gt;How did I use unary operators to solve a problem?&lt;/p&gt;

&lt;p&gt;The goal: If you are given an integer or a floating-point number, find its opposite.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Examples:
   1: -1
   14: -14
   -34: 34
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I love writing code that is easy to read, the cleanest way I thought to answer the problem was to use unary minus operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function opposite(number) {
  return(-number);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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