<?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: Cat4eve</title>
    <description>The latest articles on DEV Community by Cat4eve (@cat4er).</description>
    <link>https://dev.to/cat4er</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F924539%2F96c97906-0882-48b7-b53b-771cc4f13742.png</url>
      <title>DEV Community: Cat4eve</title>
      <link>https://dev.to/cat4er</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cat4er"/>
    <language>en</language>
    <item>
      <title>JS#2, JavaScript functions</title>
      <dc:creator>Cat4eve</dc:creator>
      <pubDate>Wed, 09 Nov 2022 19:24:36 +0000</pubDate>
      <link>https://dev.to/cat4er/js2-javascript-functions-22e1</link>
      <guid>https://dev.to/cat4er/js2-javascript-functions-22e1</guid>
      <description>&lt;p&gt;&lt;em&gt;Made by Karapet Khachatryan, AUA CS freshman student.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The second topic of this blog course would be about functions in JS. First part could be found here &lt;a href="https://dev.to/cat4er/js1-javascript-variable-differences-18i"&gt;https://dev.to/cat4er/js1-javascript-variable-differences-18i&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;During previous course we have discussed variables and their types. To explain functions, it is important to understand the oprations. There exist serveral group of opearations we will explore.&lt;/p&gt;

&lt;p&gt;1) Basic math operations ( &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt; )&lt;/p&gt;

&lt;p&gt;In JS it is very easy to make general operations we do in math. Addition, subtraction, multiplication and division are represented with unique signs. In order to apply operation, the symbol must be placed in between of two numbers or variables containing numbers.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hint, if one of the operations would not be number we are risking to get NaN (Not a Number) as an answer.&lt;/em&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;var&lt;/span&gt; &lt;span class="nx"&gt;a&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&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;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is 12 stored in variable c&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is 8 stored in variable d&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is 20 stored in variable e&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is 5 stored in variable f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Logical operations (and, or, not)&lt;/p&gt;

&lt;p&gt;The unique feature of all programming languages is that they are Turing completeness. That means that those languages contains logical operators, enough to make any logical expression. For example, A and not B and not C or A. In JS we have &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; (and), &lt;code&gt;||&lt;/code&gt; (or), &lt;code&gt;!&lt;/code&gt; (not) operators. Likewise numbers, they must be placed in between two variables or operands. However, during calculation any variable would be automatically translated into boolean language (&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;). It would be beneficial to know general rules about translation to boolean language. All inserted numbers would be equal to &lt;code&gt;true&lt;/code&gt;, excpet &lt;code&gt;0&lt;/code&gt;, which is &lt;code&gt;false&lt;/code&gt; for JS. All type of string would be equivalent to &lt;code&gt;true&lt;/code&gt;, except &lt;code&gt;''&lt;/code&gt; (empty string).&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;a&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;c&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is false stored in variable d&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is true stored in variable e&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is false stored in variable f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Comparison operators (&lt;code&gt;==&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;==&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt; are comparison operators, which compares two operands (numbers or booleans).&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&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;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&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;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&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;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is true stored in variable d&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is false stored in variable e&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is false stored in variable f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Conditional operations (&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;In JS we can make possibilities and cases and make everything happen under some conditions.&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;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&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;undereighteen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;undereighteen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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="nx"&gt;undereighteen&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;We know how to make basic operations with JS, right? Let's talk about functions!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Function in fact is a piece of code which we can use multiple time. Let's say I want to make a multiplication of two numbers, but we can only add two numbers (we can not use multiplication operation). Imagine a particular example, when we want to calculate the multiplication 2 and 3, which is 6 as we know, but our programm would be able to calculate it. We know that &lt;code&gt;2 * 3&lt;/code&gt; is the same as &lt;code&gt;2 + 2 + 2&lt;/code&gt; or &lt;code&gt;3 + 3&lt;/code&gt;. In generall if we have some x, y variables, which we want to calculate, all we need is to add x number y times or y number x times. It is time to introduce functions!&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;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&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;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&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;This is the way we define function. Likewise variables, functions have a key word, by which we define them and name, by which we remember them. Key word is not &lt;code&gt;var&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt; but the word &lt;code&gt;function&lt;/code&gt; itself is a that word, which helps JS to understand that we want to create a function. &lt;code&gt;multiply&lt;/code&gt; is the name of our function. Next, likewise functions from math, ours also have some inputs (in this case two inputs - &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;), which are considered as already defined variables. Finally, the braces (curly brackets) are setting a space, inside which our reproducable code would be written. &lt;code&gt;return&lt;/code&gt; is a key word by which our function returns us something (in math we usually call this process a map from x, y to z).&lt;/p&gt;

&lt;p&gt;Let's try to write an addition for one 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;function&lt;/span&gt; &lt;span class="nx"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&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;span class="k"&gt;if&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="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="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;span class="k"&gt;if&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="mi"&gt;2&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="o"&gt;+&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;span class="k"&gt;if&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="mi"&gt;3&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="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To call functions we write its name and general brackets, inside of which we write actual arguemnts.&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;multiply&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;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we can create a variable and assigne the return value of function to 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;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;multiply&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;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// result will be 6 stored in a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this course we have learnt the basics of functions and operations, during next course we will improve our knowledge and make better and more efficient code.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JS#1, JavaScript variable differences</title>
      <dc:creator>Cat4eve</dc:creator>
      <pubDate>Wed, 09 Nov 2022 17:33:12 +0000</pubDate>
      <link>https://dev.to/cat4er/js1-javascript-variable-differences-18i</link>
      <guid>https://dev.to/cat4er/js1-javascript-variable-differences-18i</guid>
      <description>&lt;p&gt;&lt;em&gt;Made by Karapet Khachatryan, AUA CS freshman student.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JavaScript or JS is a popular programming language all over the world. It is used by many comapnies and individuals. The language is pretty easy to understand for a newbies, since there is not such complicated stuff like typization, memory management, mandatory semicolon, etc. &lt;strong&gt;This course will be about the basics of JS to show that everyone can learn it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First of all it's important to be aware of the syntax or writing style for JS. &lt;strong&gt;Syntax predefines how the code must be written for a computer to understand.&lt;/strong&gt; There are several general strict rules and  personalized writing styles that have been developed during years among developers or programmers who had a huge experience working with JS. It will be better to show and explain in examples, explaining how code works and performs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The basics of programming are variables.&lt;/strong&gt; In math we have symbols, which we name numbers, for example, 1, -3, 4.3, etc. Same numbers exists for JS, however, in real life we memorize them unconsciously, however, computers can't do that, which means that we must tell them what to memorize. The main way we can tell computers that it must memorize something is to create a variable. &lt;strong&gt;Variable are pretty much similar to our brain cells or neurons, today's computers have enough memory to compete with people's brain capacity.&lt;/strong&gt; There is an example of JS command.&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;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a few words, we asked computer to create a variable inside its memory with &lt;code&gt;var&lt;/code&gt; word at the begining of the text line. Next, we asked computer to name that variable as &lt;code&gt;x&lt;/code&gt;, because a programmer doesn't know what exactly is going on inside the computer, so the only way not to lose the track of that variable among the terrabites of other variables is to have a name tagged with it. Finally, the semicolon or &lt;code&gt;;&lt;/code&gt; symbol is not mandatory and the same code would work equally with or without it. The semicolon has a unique story in the world of programming, but for this course we would not explore it.&lt;/p&gt;

&lt;p&gt;As i've mentioned, in JS we have general numbers and we would write them exactly in the same way. The variable we have created is empty. Likewise our brain cells, it can be stored with some kind of information. With this information, let's create a variable &lt;code&gt;x&lt;/code&gt; and give some number to store inside 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;var&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;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;What have changed from previous example?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We have introduced two new symbols - &lt;code&gt;=&lt;/code&gt; and &lt;code&gt;2&lt;/code&gt; (once again, semicolon is not necessary to have). The number two has been used as an information to be stored inside the variable &lt;code&gt;x&lt;/code&gt;, while equal sign tells us that we want to estabilish the equality between x and 2, which in the language of programming means that we want to assagine 2 to the variable x. It is important to mention that we write floating and negative numbers exactly likewise in real life, e.g. -3, 4.6, etc.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What else we can store inside those variables?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In JS we have variable types. One of them we've already learnt - numbers (&lt;code&gt;3&lt;/code&gt;, &lt;code&gt;-5&lt;/code&gt;, &lt;code&gt;3.4&lt;/code&gt;). Next, we have texts, which are named as string types. To write them we use single or multiple quotation marks (&lt;code&gt;""&lt;/code&gt; or &lt;code&gt;''&lt;/code&gt;). As an example, &lt;code&gt;"Hello"&lt;/code&gt;, &lt;code&gt;'Hola'&lt;/code&gt;, &lt;code&gt;"Bon jure"&lt;/code&gt;. Finally we will observe boolean types (named after George Bool) during this course. In boolean type there are only two expressions - &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;, which stands for truth and not truth.&lt;/p&gt;

&lt;p&gt;There have been a lot of information so, let's conclude with examples&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&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;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shalom&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;c&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Cool, we have somehow learnt about variables, right? Let's learn about the history!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Historically, in previous versions of JS there existed only one way to create a variable - &lt;code&gt;var&lt;/code&gt;, next, JS acquired two additional ways to do the same - &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt;. However, there is no need two have three equivalent expressions, hence, they have some differences. &lt;/p&gt;

&lt;p&gt;We use &lt;code&gt;const&lt;/code&gt; to define a variable which can not be changed (read only). Actually its ability is not always valid, however, this would be covered in the next topics.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; is pretty much equivalent to &lt;code&gt;var&lt;/code&gt;. The difference between them is not obvious and &lt;code&gt;let&lt;/code&gt; share that difference with &lt;code&gt;const&lt;/code&gt; too. The difference's name is variable hoisting. Since, &lt;code&gt;var&lt;/code&gt; is old it has a tiny bug, which we will observe together.&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;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&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;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hint - this code is logically wrong and must not work in general, since &lt;code&gt;5&lt;/code&gt; has been assigned to variable &lt;code&gt;x&lt;/code&gt;, and only then &lt;code&gt;x&lt;/code&gt; variable has been defined with &lt;code&gt;var&lt;/code&gt; keyword&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Since we work with JS (one of the funniest programming languages), this writing would work fine. After those two lines, the variable &lt;code&gt;x&lt;/code&gt; would have a value &lt;code&gt;5&lt;/code&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="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&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;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// or // const x;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In those cases we would have an error, which is right logically, there is no way we can work with variable without declaring it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Binary</title>
      <dc:creator>Cat4eve</dc:creator>
      <pubDate>Wed, 14 Sep 2022 17:53:19 +0000</pubDate>
      <link>https://dev.to/cat4er/binary-nmb</link>
      <guid>https://dev.to/cat4er/binary-nmb</guid>
      <description>&lt;p&gt;AUA, Karapet Khachatryan, For Intro to Computer Science course.&lt;/p&gt;

&lt;p&gt;In our everyday life, we use numbers, which are taught to us from childhood. However, it is not enough in order to communicate with computers, which were invented in the second half of 1900s. If in the real number system (which can be named as base 10 system, as it uses 10 distinct digits from 0 to 9) we have 10 digits, in binary system (base 2) we have only 0 and 1. The binary is the only way computer undertands our commands, but why? The reason is that computer works by electricity and it has various levels of frequency named Volt. Volt is a difference between potential energy of two sources. It can be imagined as the water flowing from higher potential to lower. Some levels are called 1 and others 0 (for example, 5 Volts = 1, 0.4 Volts = 0), which is named as digital system in engineering (also, there exits analog level, and it's range is distinct, but mostly from 0 to 1023). CPU (Computer's processor) is the main tool used for calculations uses digital system with some level of volts considered as 0 and 1. Here, in binary, we also have some mathematical functions likewise in base 10 system, such that.&lt;/p&gt;

&lt;p&gt;0+0 = 0&lt;br&gt;
0+1 = 1&lt;br&gt;
1+0 = 1&lt;br&gt;
1+1 = 10 (here we write 1 usually but in adders we take second digit as a carry, this will be discussed later.)&lt;/p&gt;

&lt;p&gt;The equations above are called the truth tables. This table is for adding operations. In math, adding is the same as the union of the sets, or the "or" element in logistics.&lt;/p&gt;

&lt;p&gt;0*0 = 0&lt;br&gt;
0*1 = 1&lt;br&gt;
1*0 = 0&lt;br&gt;
1*1 = 1&lt;/p&gt;

&lt;p&gt;This one is for multiplication which is the intersection for sets in math and "and" element in logistics.&lt;/p&gt;

&lt;p&gt;0^0 = 0&lt;br&gt;
0^1 = 1&lt;br&gt;
1^0 = 1&lt;br&gt;
1^1 = 0&lt;/p&gt;

&lt;p&gt;This is xor table and it has no analogs in math but it could be imagined as "a not equal to b is true, then it is false" statement.&lt;/p&gt;

&lt;p&gt;The aforementioned tables are in fact functions . To understand what is a function, we can imagine a box where we throw something and box returns us something else like a magic. Those actions are giving input to function and getting output from function. And the box is the function which does something based on input and returns us result.&lt;/p&gt;

&lt;p&gt;Before moving on, it is important to mention that with such logic we can recreate base 3, 4, 5, 6, ... systems, where we must add some distinct digit for a new base system. For example, base 16 is 0-9 then A,B,C,D,E,F&lt;/p&gt;

&lt;p&gt;The transition between base 2 and base 10 systems is a very important step of understanding binaries. Somewhere, you could have noticed numbers like 10001110, 10101010110 and so on. We already know that they are binaries, but what do they mean? Because of the specifics of various platforms, the same binary could mean different things, so we consider such numbers to be binary representation of base 10 system numbers.&lt;/p&gt;

&lt;p&gt;The question is still opened, how to find them. First it's important to understand indexes and their role for the numbers.&lt;br&gt;
13 in base 10 system have 1 and 3 digits, which means it has two indexes, the first one is 3 and second is 1. For base 2 system works exactly the same trick. 001 is binary number, which first index is 1, second is 0 and third is 0 (indexes begins with 1 and increases from right to left). In order to make base 2 to base 10 transition (b2-&amp;gt;b10) we use such formula, where we consider n to be the number of indexes and s is the sequence containing all the numbers of binary separately.&lt;/p&gt;




&lt;p&gt;s0 * 2^0 + s1 * 2^1 + ... + sn * 2^n&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: 10000 = 0 * 2^0 + 0 * 2^1 + 0 * 2^2 + 0 * 2^3 + 1 * 2^4
&lt;/h2&gt;

&lt;p&gt;In order to do b10-&amp;gt;b2 we must represent the number as the sum of powers of two (for example, 17 = 2^4 + 2^1). This is very similar to the previous one so in order to make binary from base 10 digit we take the highest power of two and write 1 then add from right 0 if the there is no power that would be smaller from highest power by one, else add 1. repeat the process till you get to the power of 0 (example, 17 = 2^4 + 2^0 = 1(4th power of 2) 0(no third power) 0(no second power) 0(no first power) 1 (0 power of 2) =&amp;gt; 10010). &lt;/p&gt;

&lt;p&gt;Talking about addition operation, I mentioned carry. The carry also exists in general math it is when the memory cell has an overflow (for example in 0-9 space we can't have 10 as it has two digits but not one). In order to make right addition operation we have half and full adders which are represented by "and", "or" and "xor" components.&lt;/p&gt;

&lt;p&gt;Half adder gets two binary digits from 0 to 1 as input and returns two digits, one of them is sum, second is carry. For example, 1 and 1 are inputs, we will have 0 as a sum and 1 as a carry. But it is called a half adder because it doesn't condiser upcomming carry from previous operations. For example 11 + 11 = 1+1 then once again 1+1, in the first case we have 0 and 1 as outputs but because of overflow for the next 1+1 we have and additionall carry, which must reult us as 1 and 1 in both outputs. Such solution is called as a full adder and it does exactly the same as pervious one but twice, for this time it also includes a third input, which is a carry from previous operations.&lt;/p&gt;

</description>
      <category>binary</category>
      <category>base2</category>
      <category>basetwo</category>
      <category>basetwotutorial</category>
    </item>
  </channel>
</rss>
