In this lecture, we're going to talk about one of the most popular new features of ESX, I'm going
to introduce you what area functions are, as we said, the main goal of release of ECMAScript 2015
version was to minimize the amount of code.
And one of the perfect examples to achieve that in Essex is to use eral functions.
First of all, I would like to mention that generally arole functions do not completely replace standard
functions which we're using as usually.
And in order to avoid unexpected results in errors, you need to definitely understand well in which
situations and in which case this is better to use function functions.
Again, in this lecture, I'm going to compare our functions to standard function declarations, so
I'm going to create a simple function expression.
Let's create constant variable multiply.
Which equals to anonymous function with two parameters, X and Y.
Inside that function, let's create let's variables that which will store the multiplication of X and
Y parameters and then return the value of Z.
OK, let's invoke dysfunction with some arguments, right, cancel that log, multiply and place here
as an arguments five and six.
Revote, and we have, of course, 13, as you see, this function expression does not contain lots
of characters and it's very easy to read.
But thanks to general functions in Essex, we can write this function in more concise way.
For that, we have to get rid of Keywood function then after parameters.
We have to place erro, which actually consists of equal and greater than signs, you may be surprised
how this function expression works without the keyboard function, but if we reload the page, then
we will get the same results.
You might think that's why do we need to replace function keyboard with that arrow?
I mean that at a glance, there is not a huge difference between the amount of code in this case and
in previous one, but actually using eral functions, we can transform this function into more concise
form.
What do we have two or more statements inside Culebra basis than in its sixth version?
We have to maintain those Kolob races, but if we return here directly X multiplied to Y without that
variable.
Then we can remove these color braces and then remove even the written keyword.
Now, we can say that this is really short and concise transformation of function expressions.
This is a really great feature.
But on the other hand, to read the code is a little bit hard, especially when you first introduced
this feature.
But I think that it's an issue of practicing.
So in this case, we have two parameters here, and that's why we surround them with parentheses.
But in case of one parameter, let's suppose we have only X, which then is multiplied to 10.
Then we don't need to use that parenthesis anymore, reload the page and you see that it works.
So, again, when we use only one parameter, we can write it without parentheses.
All right, let's see what happens if we don't have parameters, let's delete X and then write five
multiplied to ten and also remove this argument.
Reload.
And you see that we have syntax error, JavaScript engine cannot recognize what this error is here.
So when we use function expressions and we don't have parameters, then we have to place your empty
parentheses.
So you see that it works now.
OK.
Let's say we want to return as a value and object, but without using return Keywood, if we simply
create an object with property first name.
John, then we will get in counsel undefined, so in order to avoid this unexpected value, we have
just to surround this object with parentheses and that it will work.
All right, one of the key points regarding Arrow functions is that we can use them only with anonymous
functions.
If we want to declare function statements, then we have to do it in a usual way.
All right.
In this lecture, we have discussed just the basic syntactic changes about functions in ethics.
Let's move on to the next lecture in which I'm going to show you some more important features regarding
arole functions.
Let's go ahead.