<?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: Arpine Tadevosyan</title>
    <description>The latest articles on DEV Community by Arpine Tadevosyan (@arpinetadevosyan).</description>
    <link>https://dev.to/arpinetadevosyan</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%2F923026%2F6edaf51e-fab9-43d0-ab03-b80f16efe7eb.png</url>
      <title>DEV Community: Arpine Tadevosyan</title>
      <link>https://dev.to/arpinetadevosyan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arpinetadevosyan"/>
    <language>en</language>
    <item>
      <title>JavaScript Functions</title>
      <dc:creator>Arpine Tadevosyan</dc:creator>
      <pubDate>Wed, 09 Nov 2022 16:55:09 +0000</pubDate>
      <link>https://dev.to/arpinetadevosyan/javascript-functions-1m2f</link>
      <guid>https://dev.to/arpinetadevosyan/javascript-functions-1m2f</guid>
      <description>&lt;p&gt;One of the core components of JavaScript are functions. A JavaScript function is a block&amp;nbsp;of code created to perform&amp;nbsp;a certain task. We can call JavaScript function how many times we want to reuse the code.&lt;/p&gt;

&lt;p&gt;The code must accept input and return an output with an evident relationship between the input and the output in order to qualify as a function. A function must be defined someplace in the scope from which it will be called in order to be used.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Function declarations&lt;/em&gt; &lt;br&gt;
a function declaration consists of the &lt;strong&gt;function&lt;/strong&gt; keyword, followed by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The name of the function.&lt;/li&gt;
&lt;li&gt;A list of parameters to the function, enclosed in parentheses and separated by commas.&lt;/li&gt;
&lt;li&gt;The JavaScript statements that define the function, enclosed in curly brackets, { }.&lt;/li&gt;
&lt;li&gt;Inside the function, the arguments (the parameters) behave as local variables. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of a function in JavaScript&lt;br&gt;
// Function to compute the sum of x1 and x2&lt;br&gt;
function sumFunction(x1, x2) {&lt;br&gt;
  return x1 + x2;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The function sumFunction takes two parameters, called x1 and x2. The function consists of one statement that says to return the parameters of the function (that is, x1 and x2) are added together. The statement &lt;strong&gt;return&lt;/strong&gt; specifies the value returned by the function.&lt;/p&gt;

&lt;p&gt;Functions can also be created by a function expression, which can be  anonymous. For example, the function square could be been defined as:&lt;/p&gt;

&lt;p&gt;const square = function (number) {&lt;br&gt;
  return number * number;&lt;br&gt;
}&lt;br&gt;
const x = square(6); // x gets the value 36&lt;/p&gt;

&lt;p&gt;However, a function expression may include a name. Providing a name allows the function to refer to itself. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Important&lt;/em&gt;: Defining a function does not execute it. Defining it names the function and specifies what to do when the function is called (which is when the function actually performs the specified actions with the indicated parameters) &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions must be in scope when they are called, but the function declaration can be hoisted(means when the declaration appears below the call of the code).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Function scope&lt;/strong&gt;&lt;br&gt;
From the explanation of the variable, we already know that variables defined inside a function cannot be accessed from anywhere outside the function, because the variable is defined only in the scope of the function. A function, however, has access to every variable and functions defined inside the defined scope.&lt;/p&gt;

&lt;p&gt;Recursion is when the function refers to itself.&lt;/p&gt;

&lt;p&gt;There are three ways for a function to refer to itself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The function's name&lt;/li&gt;
&lt;li&gt;arguments.callee&lt;/li&gt;
&lt;li&gt;An in-scope variable that refers to the function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example with a loop.&lt;/p&gt;

&lt;p&gt;let x = 0;&lt;br&gt;
while (x &amp;lt; 10) { // "x &amp;lt; 10" is the loop condition&lt;br&gt;
  // do stuff&lt;br&gt;
  x++;&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functions</category>
      <category>programming</category>
    </item>
    <item>
      <title>JavaScript Variables</title>
      <dc:creator>Arpine Tadevosyan</dc:creator>
      <pubDate>Wed, 09 Nov 2022 12:30:16 +0000</pubDate>
      <link>https://dev.to/arpinetadevosyan/javascript-variables-58g8</link>
      <guid>https://dev.to/arpinetadevosyan/javascript-variables-58g8</guid>
      <description>&lt;p&gt;To start with, a variable in JavaScript serves as a container for a strong data, like a number we might use in a multiplication, or a string that we might use as part of a sentence. &lt;/p&gt;

&lt;p&gt;There are two types of variables in JavaScript : local variable(is visible only within a function where it is defined and accessible within the function) and global variable(can be defines anywhere in the code).&lt;/p&gt;

&lt;p&gt;While declaring a JavaScript variable, there are some rules.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Name of the variable must start with a letter, underscore( _ ), or dollar( $ ) sign.&lt;/li&gt;
&lt;li&gt;After first letter we can use digits (0 to 9), for example variable123.&lt;/li&gt;
&lt;li&gt;JavaScript variables are case sensitive, for example a and A are distinct variables.&lt;/li&gt;
&lt;li&gt;Reserved words (like JavaScript keywords) cannot be used as names.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below you can see a simple example of JavaScript variable. &lt;br&gt;
var m = 1;&lt;br&gt;&lt;br&gt;
var k = 4;&lt;br&gt;&lt;br&gt;
var z=m+k;&lt;br&gt;&lt;br&gt;
console.log(z);  &lt;/p&gt;

&lt;p&gt;VAR, LET, CONST&lt;/p&gt;

&lt;p&gt;A little about the history.&lt;br&gt;
The var keyword is used in all JavaScript code from 1995 to 2015.&lt;/p&gt;

&lt;p&gt;The let and const keywords were added to JavaScript in 2015, therefore if you want your JavaScript code to run in older browsers, you must use var.&lt;/p&gt;

&lt;p&gt;The difference between let and car&lt;br&gt;
let allows to declare variables that are limited to the scope of a block statement, or expression on which it is used. &lt;br&gt;
The var keyword declares a variable globally, or locally to an entire function regardless of block scope.&lt;/p&gt;

&lt;p&gt;We use const when we know that the value should not be changed and is a general rule(moreover, when someone will look at our code and see const, they will immediately understand that this name will never be assigned to a different value. Any time they see this name, they will know what it refers to.).&lt;/p&gt;

&lt;p&gt;"Use const when you can, and use let when you have to."&lt;/p&gt;

&lt;p&gt;JavaScript Scope&lt;br&gt;
Scope determines the accessibility of variables, there are 3 types of Scopes - Block scope, Function scope and Global scope.&lt;/p&gt;

&lt;p&gt;Block Scope&lt;br&gt;
let and const keywords provide Block Scope in JavaScript. (you can see that var is not included, the reason I will explain later)&lt;br&gt;
Variables declared inside a { } block cannot be accessed from outside the block:&lt;br&gt;
Example&lt;/p&gt;

&lt;p&gt;{&lt;br&gt;
  let x = 6575;&lt;br&gt;
}&lt;br&gt;
// x can NOT be used here&lt;/p&gt;

&lt;p&gt;var cannot have block scope, because var declares variable globally, for the whole code.&lt;br&gt;
Example&lt;/p&gt;

&lt;p&gt;{&lt;br&gt;
  var a = 111;&lt;br&gt;
}&lt;br&gt;
// a CAN be used here&lt;/p&gt;

&lt;p&gt;Function Scope&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;var, let and const have function scope.&lt;/li&gt;
&lt;li&gt;each function creates a new scope.&lt;/li&gt;
&lt;li&gt;variables defined inside a function are not visible when we get out of function.
Example&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;function ourFunction() {&lt;br&gt;
  let countryName = "Armenia";   // Function Scope&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Global Scope&lt;br&gt;
(a variable is global when it is defined outside a function)&lt;/p&gt;

&lt;p&gt;Variables declared Globally have Global Scope.&lt;/p&gt;

&lt;p&gt;In a JavaScript program, global variables can be accessed from anywhere.&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;let bookName = "Xenty";&lt;br&gt;
// code here can use bookName&lt;/p&gt;

&lt;p&gt;function theFunction() {&lt;br&gt;
// code here can also use bookName&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>variables</category>
      <category>programming</category>
    </item>
    <item>
      <title>Binary numbers</title>
      <dc:creator>Arpine Tadevosyan</dc:creator>
      <pubDate>Tue, 13 Sep 2022 15:01:24 +0000</pubDate>
      <link>https://dev.to/arpinetadevosyan/binary-numbers-2m36</link>
      <guid>https://dev.to/arpinetadevosyan/binary-numbers-2m36</guid>
      <description>&lt;p&gt;Unlike our known decimal system, which uses 10 as a base and is aimed to calculate practically everything in our everyday life, binary numbers are used in computer applications. From the root of the word it becomes obvious that in this system the base is 2 and the numbers are represented by only two symbols or digits - 1 and 0. However, we can represent every single number within using only two digits (for example numbers from 0 to 10 we can represent as 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, and 1010 (I will show how to get these numbers a bit later)). The binary system is significant for information theory and computer technology because it is compact and reliable in order to be represented in electromechanical devices with two states such as “1-on - 0-off,” “1-open - 0-closed,” or “1-go – 0-no go". &lt;/p&gt;

&lt;p&gt;In general, a binary number is longer than its corresponding decimal number. For example, the 1234567 number in the decimal system equals to 100101101011010000111 represented binary. The binary number is longer because a binary digit only distinguishes between the possibilities of 0 or 1 whereas a decimal digit distinguishes among 10 possibilities. To put it in another way, a binary digit carries less information than a decimal digit. &lt;/p&gt;

&lt;p&gt;Every digit is referred to as a bit: a bit of information is transmitted whenever one of two alternatives is realized in the machine. For instance 1001101 is a seven-bit number, 1010 is a four-bit binary number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Relation between decimal and binary numbers
&lt;/h2&gt;

&lt;p&gt;Let's take a random decimal number and convert it to a binary number.&lt;/p&gt;

&lt;p&gt;For example 5 in binary is (101)2.&lt;/p&gt;

&lt;p&gt;In this example, the decimal number system is used to represent the number 5, and the digits 0 through 9 can be used to do so. In contrast, as I mentioned above a binary number system simply employs two digits, 0 and 1. &lt;/p&gt;

&lt;p&gt;Now, let’s understand how to convert 5 in the binary number system. The following steps help to convert 5 in binary.&lt;/p&gt;

&lt;p&gt;Step 1: First, we should divide the number 5 by 2. Use the integer quotient obtained in this step as the dividend for the next step. Continue this step, until the quotient becomes 0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XMd8PXws--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw77pqirsh2r9cx4osuf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XMd8PXws--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw77pqirsh2r9cx4osuf.png" alt="Image description" width="880" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 2: Now, we should write the remainder in reverse chronological order. (i.e from bottom to top).&lt;br&gt;
Here, the Least Significant Bit (LSB) is 0 and the Most Significant Bit (MSB) is 1.&lt;br&gt;
Hence, the decimal number 5 in binary is (101)2&lt;/p&gt;

&lt;p&gt;The number of bits of the number 5 in binary is 3.&lt;/p&gt;

&lt;p&gt;Now let's take a binary number and convert it to a decimal number.&lt;/p&gt;

&lt;p&gt;For example, if we take binary number 101, then we can divide the number into columns. Starting from the right side, there is 1 in the first column, 0 in the second column and again 1 in the third column. Now, we should multiply each column with the powers of 2, starting from 0 and right hand side, like depicted in the picture. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RVM5Gcd---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7fkao43fh6g7ynifjwvf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RVM5Gcd---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7fkao43fh6g7ynifjwvf.jpg" alt="Image description" width="345" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The number can be converted to decimal by multiplying out as follows:&lt;br&gt;
1*1 + 0*2 + 1*4 = 5&lt;br&gt;
Simple calculations show that 101 in the binary system equals 5 in the decimal system. &lt;/p&gt;

&lt;p&gt;The same way we can convert any binary number. Another example to clarify the process.&lt;br&gt;
Let's take 1101. Now we should do some calculations.&lt;br&gt;
1*1 + 0*2 + 1*4 + 1*8 = 13&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c6dsszUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/593708rfaieury8rmneb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c6dsszUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/593708rfaieury8rmneb.jpg" alt="Image description" width="100" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1101 in binary system is 13 in decimal system. &lt;/p&gt;

&lt;h2&gt;
  
  
  Binary Addition
&lt;/h2&gt;

&lt;p&gt;Adding two binary numbers will give us a binary number itself. It is the simplest method. The table below shows the addition of two binary numbers with one digit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0Ktz2hbL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ai0hyiogtlk25tiy1gyk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0Ktz2hbL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ai0hyiogtlk25tiy1gyk.png" alt="Image description" width="880" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you see, adding 1 and 1 gives us carry 1. Like in decimal system addition, we move the carry to the next step and continue calculating considering the carry. &lt;br&gt;
For example, let's add 1101 and 1001.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ddo92wRT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwtdtash6saduecvh94b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ddo92wRT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwtdtash6saduecvh94b.png" alt="Image description" width="218" height="290"&gt;&lt;/a&gt;&lt;br&gt;
As you can see in the last step we had a carry, so we put the 1 immediately in the answer because there was no steps left. So the answer is 10110.&lt;/p&gt;

&lt;h2&gt;
  
  
  Binary Subtraction
&lt;/h2&gt;

&lt;p&gt;Subtracting two binary numbers will give us a binary number too. It is also a straightforward method. Subtraction of two single-digit binary number is given in the table below.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yQqr2Vuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1afczfz8btlhik3bxyls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yQqr2Vuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1afczfz8btlhik3bxyls.png" alt="Image description" width="880" height="307"&gt;&lt;/a&gt;&lt;br&gt;
For instance, let's subtract 1101 and 1010. The solution will be &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8XjVsiB8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekmju8h0arwxc8n6vian.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8XjVsiB8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekmju8h0arwxc8n6vian.png" alt="Image description" width="235" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the second step, we see that we should subtract 1 from 0. Therefore, we borrow 1 from the 0's left side neighbor 1 and in the result we get 1. However, as we already borrowed 1, the next step will be 0 - 0 which equals to 0. &lt;/p&gt;

&lt;h2&gt;
  
  
  Binary Multiplication
&lt;/h2&gt;

&lt;p&gt;The multiplication process is the same for the binary numbers as it is for numerals. Let's look at an example. &lt;br&gt;
 Multiply 1101 and 1010&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HdFNINlc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnp2tvm2tguns13dzi94.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HdFNINlc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnp2tvm2tguns13dzi94.png" alt="Image description" width="153" height="266"&gt;&lt;/a&gt;&lt;br&gt;
First, we multiply the first number by 0. Then emitting one symbol, multiplying the same number by 1 and so on. I want to repeat that in this step multiplication in binary system is the same as in decimal system. Afterwards, we add the binary numbers like I showed above and finally get the desired number.&lt;/p&gt;

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