<?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: Edgar Minasyan</title>
    <description>The latest articles on DEV Community by Edgar Minasyan (@edgarminasyan14).</description>
    <link>https://dev.to/edgarminasyan14</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%2F926935%2F56ec6b84-a9a7-433f-8570-fa70c63ee448.png</url>
      <title>DEV Community: Edgar Minasyan</title>
      <link>https://dev.to/edgarminasyan14</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/edgarminasyan14"/>
    <language>en</language>
    <item>
      <title>Functions in JavaScript</title>
      <dc:creator>Edgar Minasyan</dc:creator>
      <pubDate>Wed, 09 Nov 2022 20:03:31 +0000</pubDate>
      <link>https://dev.to/edgarminasyan14/functions-in-javascript-17gn</link>
      <guid>https://dev.to/edgarminasyan14/functions-in-javascript-17gn</guid>
      <description>&lt;p&gt;In this blog, we are going to speak about the functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are functions
&lt;/h2&gt;

&lt;p&gt;Simply put, a function is a piece of code that you can reuse repeatedly rather than having to write it out several times. Programmers can divide a problem into smaller, more manageable parts, each of which can carry out a specific task, using functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to declare a function in JS
&lt;/h2&gt;

&lt;p&gt;The function keyword is used to define a JavaScript function, which is then followed by the function's name and parentheses ().&lt;/p&gt;

&lt;p&gt;Function names may also include underscores, dollar signs, and other characters (same rules as variables).&lt;/p&gt;

&lt;p&gt;Names of parameters may be enclosed in parentheses and separated by commas: (parameter1, parameter2, ...)&lt;/p&gt;

&lt;p&gt;Curly brackets enclose the code that the function will execute: {}&lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;

&lt;p&gt;function name(parameter1, parameter2, parameter3) {&lt;br&gt;
  // code to be executed&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Function parameters are listed inside the parentheses () in the function definition.&lt;/p&gt;

&lt;p&gt;Function arguments are the values received by the function when it is invoked.&lt;/p&gt;

&lt;p&gt;Inside the function, the arguments (the parameters) behave as local variables.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;function sum(x, y){&lt;br&gt;
    console.log(sum);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;However, when we write this function it doesn't print anything in the console. To make our function work we should first call our function. To do this, we need to write the function's name, add the symbol (), and, if the function asks for it, write the values we want to pass it inside ().&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
function sum(x, y){&lt;br&gt;
    console.log(sum);&lt;br&gt;
}&lt;br&gt;
sum(4,5)//this will print 4+5 which is equal to 9&lt;/p&gt;

&lt;h2&gt;
  
  
  Return statement
&lt;/h2&gt;

&lt;p&gt;The return statement ends the function execution and specifies a value to be returned to the function caller.&lt;br&gt;
For example, the following function returns the square of its argument, x, where x is a number.&lt;/p&gt;

&lt;p&gt;function square(x) {&lt;br&gt;
  return x * x;&lt;br&gt;
}&lt;br&gt;
const demo = square(3);&lt;br&gt;
// demo will equal 9&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functions</category>
      <category>programming</category>
    </item>
    <item>
      <title>Variables in JavaScript, differences between var, let, const. What are scopes? What is the visibility for the variable?</title>
      <dc:creator>Edgar Minasyan</dc:creator>
      <pubDate>Wed, 09 Nov 2022 19:07:52 +0000</pubDate>
      <link>https://dev.to/edgarminasyan14/variables-in-javascript-differences-between-var-let-const-what-are-scopes-what-is-the-visibility-for-the-variable-51g</link>
      <guid>https://dev.to/edgarminasyan14/variables-in-javascript-differences-between-var-let-const-what-are-scopes-what-is-the-visibility-for-the-variable-51g</guid>
      <description>&lt;p&gt;In this blog post, you will learn about variables in JavaScript, how to declare them, and the difference between var, let, and const, and we will speak about scopes and the visibility of the variables. So, let’s start.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a variable and how to declare them?
&lt;/h2&gt;

&lt;p&gt;A variable is a label that references a value like a number or string. Before using a variable, you need to declare it.&lt;/p&gt;

&lt;p&gt;To declare a variable, you use the var keyword followed by the variable name as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;           var age;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A variable name can be any valid identifier. By default, the name variable has a special value undefined if you have not assigned a value to it. &lt;/p&gt;

&lt;p&gt;Variable names follow these rules: &lt;br&gt;
• Variable names are case-sensitive. This means that the message and Message are different variables. &lt;br&gt;
• Variable names can only contain letters, numbers, underscores, or dollar signs and cannot contain spaces. Also, variable names must begin with a letter, an underscore (_) or a dollar sign ($). &lt;br&gt;
• Variable names cannot use already used words. &lt;/p&gt;

&lt;p&gt;JavaScript is a dynamically typed language. This means that you don’t need to specify the variable’s type in the declaration. &lt;br&gt;
You can also use the let keyword to declare a variable:&lt;/p&gt;

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

And you can also use the const keyword to declare a variable:

                   const surname;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Later, in this blog post, we will speak about the differences between var, let, and const keywords. &lt;/p&gt;

&lt;p&gt;Once you have declared a variable, you can give a value to it. To do so , you specify the variable name, followed by an equals sign (=) and a value. &lt;br&gt;
For example, The following declares the word variable and gives it this string value "Hello":&lt;br&gt;
        var word;&lt;br&gt;
        word = “Hello”;&lt;br&gt;
You can give a value to the variable at the same time you declare it:&lt;br&gt;
                var word = “Hello”;&lt;/p&gt;

&lt;p&gt;Once you initialize a variable, you can change its value by assigning a different value. For example:&lt;br&gt;
                var word = “Hello”;&lt;br&gt;
                word  = “bye”;&lt;br&gt;
                console.log(word); //bye&lt;/p&gt;

&lt;h2&gt;
  
  
  Undefined vs. undeclared variables
&lt;/h2&gt;

&lt;p&gt;It’s important to distinguish between undefined and undeclared variables.&lt;br&gt;
    An undefined variable is a variable that has been declared but has not been initialized with a value. For example:&lt;br&gt;
                var word;&lt;br&gt;
                console.log(word); //undefined&lt;br&gt;
In this example, the word variable is declared but not initialized. Therefore, the word variable is undefined. &lt;br&gt;
In contrast, an undeclared variable is a variable that has not been declared. For example:&lt;br&gt;
        console.log(names); //This will give an error&lt;/p&gt;

&lt;h2&gt;
  
  
  Constants
&lt;/h2&gt;

&lt;p&gt;A constant holds a value that doesn’t change. To declare a constant, you use the const keyword. When defining a constant, you need to initialize it with a value. For example:&lt;br&gt;
                const a = 5;&lt;/p&gt;

&lt;p&gt;Once defining a constant, you cannot change its value. The following example attempts to change the value of the a constant to 4 and causes an error:&lt;br&gt;
                a = 4;//this will give an error&lt;/p&gt;

&lt;h2&gt;
  
  
  The difference between var and let.
&lt;/h2&gt;

&lt;p&gt;As we know programming languages are made of lots of different operators and tools, such as loops, conditions, functions, and so on. All these tools become complete with the help of blocks. By saying block of code I mean the place where our code is situated. Usually, the start of the block is denoted with { this symbol, and the end of the block with this symbol }. &lt;br&gt;
For example:&lt;br&gt;
{&lt;br&gt;
    var x = 10; &lt;br&gt;
}&lt;br&gt;
console.log(x)//10&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In this case, the variable x is declared inside the block, but then we use console.log(x) outside the block it will still work. However, if we used let instead of var it would not work:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;{&lt;br&gt;
    let x = 10;&lt;br&gt;
}&lt;br&gt;
console.log(x);//error&lt;/p&gt;

&lt;p&gt;This work by this way, because there are two types of variables: global and local. When we declare variable with var it declares global variable, which we can use even outside the block where it was decalered. And when we use let to declare the variable it declares local variable which can be only used inside the block where it was declared. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>variables</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What are binary number? Why we need them? How to convert Binary to decimal? How to add and multiple binary number?</title>
      <dc:creator>Edgar Minasyan</dc:creator>
      <pubDate>Thu, 15 Sep 2022 19:21:04 +0000</pubDate>
      <link>https://dev.to/edgarminasyan14/what-are-binary-number-why-we-need-them-how-to-convert-binary-to-decimal-how-to-add-and-multiple-binary-number-32pi</link>
      <guid>https://dev.to/edgarminasyan14/what-are-binary-number-why-we-need-them-how-to-convert-binary-to-decimal-how-to-add-and-multiple-binary-number-32pi</guid>
      <description>&lt;p&gt;What are binary numbers?&lt;/p&gt;

&lt;p&gt;Binary numbers are numbers which are expressed in base-2 numerical system or binary numerical system. It’s a method of mathematical expression which uses only two symbols: 0 and 1. So to represent numbers starting from zero in base-2 numerical system we just start from 0(0 in base-10), 1(1 in base-10), 10(2in base-10), 11(3 in base-10), 100(4in base-10) and so on. Every digit in our base-2 numbers is referred to as a bit or a binary digit.&lt;/p&gt;

&lt;p&gt;So why do we need this base-2 numerical system?&lt;/p&gt;

&lt;p&gt;The main reason the binary number system is used in computing and it is simpler for computers to understand the language or numbers in the same way that we do. All that computers really have available to work with are switches and electrical signals, which are either on or off. So, to say it much simpler if we have 1 it means there is an electricity if we have 0 it means that there is no electricity. &lt;/p&gt;

&lt;p&gt;How to convert binary to decimal?&lt;/p&gt;

&lt;p&gt;If you are given a binary number and you need to understand which decimal number that could be you jut need to do the following to get decimal value of that number.                                    Since binary numbers are type of positional number system. That means Weight of the positions from right to left are as 2^0, 2^1, 2^2,2^3 … and so on. So, starting from the right side you just multiple your binary digit into 2^(digit’s position) and add all numbers that you got from multiplying.&lt;br&gt;
        For example: 1101 = 1*2^3 + 1*2^2 + 0*2^1 + 1*2^0 = 8+4+0+1 = 13&lt;/p&gt;

&lt;p&gt;How to add and multiply binary numbers?&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                        Adding
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The binary addition operation works similarly to the base 10 decimal system, except that it is base 2 system and it consist of only two digits. In binary addition we again start from the right. Binary addition is much easier than the decimal addition if you remember just this four rules of binary addition: &lt;br&gt;
• 0 + 0 = 0&lt;br&gt;
• 0 + 1 = 1&lt;br&gt;
• 1 + 0 = 1&lt;br&gt;
• 1 + 1 = 10&lt;br&gt;
Now, look at the example of binary addition: 101 + 101&lt;br&gt;
Step 1: First consider 1’s column from the right, and add the digits of that column (1+1) and it gives the result 10&lt;br&gt;
Step 2: Now, leave the 0 in the one’s column and carry the value 1 to the 10’ column&lt;br&gt;
Step 3: Now add 10’s place, 1+(0+0) = 1. So, nothing carries to the 100’s place and leave the value 1 in the 10’s place&lt;br&gt;
Step 4: Now add the 100’s place (1+1)=10. Leave the value 0 in the 100’s place and carries 1 to the 1000’s place&lt;br&gt;
        Result: So in the end by adding 101 to 101 we get 1010.     &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                      Multiplying 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Binary multiplication is similar to the multiplication of decimal numbers. We have a multiplier and a multiplicand. The result of multiplication result in a product. Since only binary digits are involved in binary multiplication, we get to multiply only 0s and 1s. The rules for binary multiplication are as follows.&lt;br&gt;
• 0 * 0 = 0&lt;br&gt;
• 0 * 1 = 0&lt;br&gt;
• 1 * 0 = 0&lt;br&gt;
• 1 * 1 = 1&lt;br&gt;
 And you just multiply binary numbers as you multiply decimals by using this rules.&lt;/p&gt;

</description>
      <category>binary</category>
      <category>adding</category>
      <category>multiplying</category>
      <category>converting</category>
    </item>
  </channel>
</rss>
