<?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: Axel Yaguana</title>
    <description>The latest articles on DEV Community by Axel Yaguana (@axlyaguana11).</description>
    <link>https://dev.to/axlyaguana11</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%2F604193%2F07d6750e-4fc4-4426-a4cd-2e4f59f01420.jpg</url>
      <title>DEV Community: Axel Yaguana</title>
      <link>https://dev.to/axlyaguana11</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/axlyaguana11"/>
    <language>en</language>
    <item>
      <title>Learn About JavaScript Functions in 3 Minutes ⏱️</title>
      <dc:creator>Axel Yaguana</dc:creator>
      <pubDate>Tue, 06 Apr 2021 15:47:42 +0000</pubDate>
      <link>https://dev.to/axlyaguana11/learn-about-javascript-functions-in-3-minutes-3a86</link>
      <guid>https://dev.to/axlyaguana11/learn-about-javascript-functions-in-3-minutes-3a86</guid>
      <description>&lt;p&gt;No matter what programming language you pick up to develop strong software, you always end up using functions to &lt;strong&gt;make code more effective&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;A function is a piece of code that performs a task, it's made to be reusable and saves many coding lines. Do you remember your algebra classes? Well, a JavaScript function is similar to those of your math lectures in a certain way. &lt;/p&gt;

&lt;p&gt;So, in this blog &lt;strong&gt;you're going to learn about JavaScript functions&lt;/strong&gt; and how to use them.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcloudreports.net%2Fwp-content%2Fuploads%2F2019%2F06%2FFunction_machine2.png" 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%2Fcloudreports.net%2Fwp-content%2Fuploads%2F2019%2F06%2FFunction_machine2.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding a JavaScript function syntax
&lt;/h2&gt;

&lt;p&gt;A function has a name, input arguments, its logics and something to output. So, basically, the syntax of a function in JavaScript is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myFunc(arg1, arg2, arg3) {
     //Function logics
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;function&lt;/code&gt; is the reserved word to make JavaScript understand it's a function.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;myFunc&lt;/code&gt; is your function's name. You can use any name, but you may want a name that makes sense to you.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arg1&lt;/code&gt;, &lt;code&gt;arg2&lt;/code&gt;, &lt;code&gt;arg3&lt;/code&gt; ... are the input arguments. They can be as many as you need. Or your function may need no argument at all.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;//Function logics&lt;/code&gt; is into curly braces &lt;code&gt;{}&lt;/code&gt; and this is where all the magic of the function happens. It contains the code to be executed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Function Expression
&lt;/h2&gt;

&lt;p&gt;In JavaScript you can &lt;strong&gt;store&lt;/strong&gt; a function in a variable and invoke it with the variable name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const multiplicacion = function mult(num1, num2) {
     return num1 * num2
}
```


Now, if we want to invoke this function, we code this:


```
const operacion = multiplicacion(3, 4)

//Expected output: 12
```


**BE CAREFUL!** You can't call `mult` as a function, it will return an error:


```
const operacion2 = mult(3, 4)

//Expected output: Uncaught ReferenceError: mult is not defined
```



Notice the keyword `return`. This makes a function to return something.

## Anonymous Function
Yes, you can define a function with no name. They're useful while passing a callback function or creating a closure.


```
const anonimo = function () {
     console.log('It is an anonymous function')
}

anonimo()

//Expected output: It is an anonymous function
```


## Arrow Functions

![](https://miro.medium.com/max/3200/1*UayxZEMi_mVgb14UC_zHyw.png)

Arrow functions were implemented in **ECMAScript 6**. The main benefit is less code since you can create a function in just one line!

Let's compare an arrow function to a traditional one:



```
//Traditional Function
const traditionalGreeting = function (name){
     return `Hi, ${name}`
}


//Arrow Function
const arrowGreeting = (name) =&amp;gt; `Hi, ${name}`


traditionalGreeting('Maria')
//Expected output: Hi, Maria

arrowGreeting('Axel')
//Expected output: Hi, Axel
```


See how we can create the same traditional function in just one code line. If you'd like me to write a post about arrow functions let me know in the comments section.

## Function Scope
When you declare a variable inside a function, you can't access to it from anywhere outside. Let's see this example which raises a number to the second power


```
const funcScope = secondPower(numero) {
     const power = 2
     return numero * power
}

//Here you can't access power
```


Accessing `power` outside the function is not be possible. 

## Invocation vs Referencing 
To invoke a function means to call it and to execute it. On the other hand, to reference a function is just that, to make your program know there's a function anywhere else. 

Imagine you have a function called `myFunc`. So, if you just want to make reference to it, you type `MyFunc`. On the contrary, if you want to invoke it, you type `myFunc()`. Notice the parenthesis `()`. But to understand it better, let's see an example using events.

In this example there's a button and when the user clicks it, it shows an alert saying 'Hello!'.

We have this structure in HTML:


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Click Me&lt;/p&gt;

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

In JavaScript we have this:


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;const sayHello = () =&amp;gt; alert('Hello!')&lt;/p&gt;

&lt;p&gt;const boton = document.querySelector('button')&lt;/p&gt;

&lt;p&gt;boton.addEventListener('click', sayHello)&lt;/p&gt;

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

As you see, in the line `boton.addEventListener('click', sayHello)` the arguments are `'click'` (the event) and `sayHello` (a function). But the latest is just being referenced, since **we don't need it to be executed** unless the user clicks the button.

So far, you have learned the basics of JavaScript functions. The key to become a good developer is practice. So I ask you to **write your own functions** and to practice all you need. 

If you liked what you read, you can subscribe my posts. Or you can follow me on [Twitter](https://twitter.com/axlyaguana11). I'll be glad to hear you opinions. 



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Concepts You Need to Know If You are a JavaScript Beginner</title>
      <dc:creator>Axel Yaguana</dc:creator>
      <pubDate>Tue, 30 Mar 2021 18:09:52 +0000</pubDate>
      <link>https://dev.to/axlyaguana11/concepts-you-need-to-know-if-you-are-a-javascript-beginner-5am0</link>
      <guid>https://dev.to/axlyaguana11/concepts-you-need-to-know-if-you-are-a-javascript-beginner-5am0</guid>
      <description>&lt;p&gt;JavaScript is undoubtedly a &lt;strong&gt;must have&lt;/strong&gt; if you want to become a web developer. That's because it allows you to create web apps which interact with users. &lt;/p&gt;

&lt;p&gt;So, if you're a JavaScript beginner, I'll tell you some basics to get into context and &lt;strong&gt;make your learning curve smoother&lt;/strong&gt;. This way you'll understand the background instead of doing a copy-paste of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables: types, initialization and declaration
&lt;/h2&gt;

&lt;p&gt;A variable is a representation somewhere in memory that stores a value. You can declare and initialize a variable in just one code line:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Alternatively, you can first declare the variable and then initialize it (with more than one line):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var x;  // Declaration
x = 5;  // Initialization
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;var&lt;/code&gt; vs &lt;code&gt;let&lt;/code&gt; vs &lt;code&gt;const&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Before ECMAScript 6 (2015), the only way to declare a variable was using &lt;code&gt;var&lt;/code&gt;. But now you can use &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;. The main differences have to do with scope, re-assignation and hoisting.&lt;/p&gt;

&lt;p&gt;To put it simple, &lt;code&gt;var&lt;/code&gt; has global/function scope, that's to say, you can access to this variable from anywhere in your code, except if you declared it in a function. Function scope means you can access your variable just inside the function itself. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; have block scope, that means you can access to them just in the block code they are declared. You can understand it better after analyzing this table:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FEeVw-DOXgAAMtKk%3Fformat%3Djpg%26name%3D900x900" 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%2Fpbs.twimg.com%2Fmedia%2FEeVw-DOXgAAMtKk%3Fformat%3Djpg%26name%3D900x900" alt="Comparison var, let, const"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I suggest you using &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; rather than &lt;code&gt;var&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;A function is a &lt;strong&gt;block of code that perform a task&lt;/strong&gt;. They're useful when writing web apps since they make code more readable. As a JavaScript beginner, you have all you need to understand functions.&lt;/p&gt;

&lt;p&gt;In general, every function in all programming languages have a name, arguments to input and a result to output. By the way, there're functions that don't need arguments to be invoked. &lt;/p&gt;

&lt;p&gt;The syntax of a JavaScript function is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function func_name(arg1, arg2, arg3){
     //code to be executed
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;function&lt;/code&gt; is the reserved word to declare a function.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;func_name&lt;/code&gt; is your function name. You can name it however you want, but I recommend a name that makes sense to you.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arg1&lt;/code&gt;, &lt;code&gt;arg2&lt;/code&gt;, &lt;code&gt;arg3&lt;/code&gt; are the function's arguments. You can require as many as you want (or zero).&lt;/li&gt;
&lt;li&gt;The line &lt;code&gt;//code to be executed&lt;/code&gt; makes reference to the logics of your function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's see an example of a function that returns the addition of two numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Declaring the function
function esSuma(num1, num2){
     return num1 + num2
}

//Executing the function
let x = esSuma(3, 4)     //You assign the function to a variable
console.log(x)          //It prints 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Arrow Functions
&lt;/h3&gt;

&lt;p&gt;A new way to declare functions is &lt;strong&gt;arrow functions&lt;/strong&gt;. As you advance as a developer, you'll see that arrow functions are &lt;strong&gt;easy to read&lt;/strong&gt; and, sometimes, more adequate than the normal ones.&lt;/p&gt;

&lt;p&gt;This is the syntax of an arrow function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const x = (arg1, arg2) =&amp;gt; {
     //Code to be executed
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'll be explaining the use of arrow functions and normal functions in other post (coming soon).&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/understanding-variables-scope-hoisting-in-javascript#:~:text=Scope%20in%20JavaScript%20refers%20to,declared%20inside%20of%20a%20block" rel="noopener noreferrer"&gt;Scope&lt;/a&gt; in JavaScript is how accessible a variable is. There are basically two types: Local Scope and Global Scope.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local Scope
&lt;/h3&gt;

&lt;p&gt;You can access your variable just inside the block code or function it's declared. For example in a function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Here you can't access your y

function hola() {
     let y = 3
     console.log(y)
}

//Here you can't y
//y is considered to have function scope as well
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the same way, in a block code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Here you can't access x
{
     let x = 5
}

//Here you can't access x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that I declared &lt;code&gt;x&lt;/code&gt; using &lt;code&gt;let&lt;/code&gt;. If I did the opposite, using &lt;code&gt;var&lt;/code&gt; you could access the variable outside the block code. It turns out that &lt;code&gt;var&lt;/code&gt; declares a global variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Global Scope
&lt;/h3&gt;

&lt;p&gt;In this case you can access your variable wherever in your code. For example:&lt;br&gt;
&lt;/p&gt;

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

{
     //Here you can access w
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you read before, if you declare a variable using &lt;code&gt;var&lt;/code&gt;, you create a global variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var q = 1

//q is a global variable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Arrays
&lt;/h2&gt;

&lt;p&gt;Arrays are a type of variable developed to store multiple variables of multiple types. They're useful when you need to store many values related to a single variable.&lt;/p&gt;

&lt;p&gt;For instance, imagine you're managing a group of people:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let people = ['Axel', 'Diego', 'Sofia', 'Valeria']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the syntax of an array is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arrayName = [item1, item2, item3 ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can modify arrays using &lt;a href="https://www.w3schools.com/js/js_arrays.asp" rel="noopener noreferrer"&gt;methods&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objects
&lt;/h2&gt;

&lt;p&gt;Objects are representations of real life things into code. So an object has properties (its characteristics) and methods (things the object can do). Let's create an object called &lt;code&gt;axel&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let axel = {
    height: 183,
    country: 'Ecuador',
    profession: 'Developer',
    returnInfo: function () {
        return this.height + ' ' + this.country + ' ' + 
        this.profession
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, properties are &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;country&lt;/code&gt; and &lt;code&gt;profession&lt;/code&gt;. You can access them using dot (.) notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axel.country
//Expected output: 'Ecuador'

axel.profession
//Expected output: 'Developer'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the other hand, &lt;code&gt;returnInfo&lt;/code&gt; is an especial property that has a function as value. That's why it's a method. You can invoke this method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axel.returnInfo()

//Expected output: '183 Ecuador Developer'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why did we use &lt;code&gt;this&lt;/code&gt; while coding the element method?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; makes reference to the object itself. So we are considering &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;country&lt;/code&gt; and &lt;code&gt;profession&lt;/code&gt; of &lt;code&gt;axel&lt;/code&gt;. It's an important word to take into account.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generating Object Templates
&lt;/h3&gt;

&lt;p&gt;What if you have to create too many many objects of the same type? Creating 'manually' each of them is not efficient. So, to solve this problem you can use Object Templates.&lt;/p&gt;

&lt;p&gt;Basically you create a function and, from this function, you create your objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Usuario(height, country, profession) {
    this.height = height,
    this.country = country,
    this.profession = profession
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets create an object using &lt;code&gt;Usuario&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let juanito = new Usuario(176, 'Uruguay', 'Designer')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;juanito&lt;/code&gt; is created and you can access its properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;juanito.country
//Expected output: 'Uruguay'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These were some concepts you need to understand to make your &lt;strong&gt;learning path more productive&lt;/strong&gt;. Basics of JavaScript are essential for every web developer.&lt;/p&gt;

&lt;p&gt;If you're a JavaScript beginner and you think it's a lot of information, don't give up. You can master this and acquire more knowledge as time passes by. &lt;strong&gt;I challenge you to become a JavaScript Ninja&lt;/strong&gt;. This is the beginning.&lt;/p&gt;

&lt;p&gt;If you liked this post, &lt;strong&gt;you can subscribe&lt;/strong&gt;. I'll continuously update blogs that may help you in your career as a developer.  &lt;/p&gt;

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