In this lesson, we're going to be looking at the new six era format for functions, so it's a shorthand
way of writing functions.
And I did want to expose you to this.
It's available in most of the browsers are going to be compatible with S6 and some of the older browsers
may not be so always keep that in mind when you are using the newer format.
So this is an example of how to rate the function expression and the format is the same thing.
So this is the one that we've got it up here at the top.
And then down here we've got this short arrow format for functions.
So notice that the word function is gone.
All we have is the rounded brackets.
We're still able to pass in arguments and parameters.
And then we've got this equal sine and the greater than sine.
And then what we're returning back is the X times five.
So this is how we can write the function and the output is going to be the same thing.
So if you're to test this out, you're able to see that it outputs it within the same format.
So there's also a really great resource, which is the Bible.
James eyehole on line.
And this gives you the ability to convert JavaScript code to older versions.
So if you did want to check that out, it's always a really good resource to check out and to get more
familiar with.
So if you do want to make your JavaScript code more compatible or older compatible, you can copy it
in here and have it rendered out into the older format.
So if you were to take our example where we've got VAR or we're going to do the new version where we've
got const test 11 and then the equals sign, we're passing in the argument, what we're doing is we're
taking the value of X and we're multiply it by five to return a value right away.
It's, it's already showing us that example.
So this is how it would have been written within the older versions of JavaScript.
So we've got a bunch of presets here and we can convert it to different versions of JavaScript.
So really handy resource, especially when you want to make your content more backwards compatible.
So I do suggest that you do try that one out.
So in order to write the arrow functions, the formats, you need to declare the variable, of course,
and give it a name of the function in order so that you can invoke it later on, that you can connect
to it later on.
You also need to define the body within the curly brackets.
So just as any other function, the way that it works is that we have the body of the function within
the curly brackets.
So the challenge for this lesson is to convert one of the earlier functions that we used in the course
to the newer format with the Arrow function format.
So you can take any one of the functions.
And we've had plenty of examples.
You can go back or you can create your own as a sample, collect any function you want to try it out
and get familiar with it.
Go ahead, pause the video and we'll walk you through a solution.
Coming up, it's opening up the header and the way that we've been writing them before.
So we're passing in an argument.
We can use X as well.
And in this case, we're going to return X, multiply it by 10 and we'll put it into the console.
So take that variable, that function test, pass it into and output it into the console so we get back
nine hundred.
So that worked.
Now let's convert this into the Arrow format where we've got tests, you can call it test two.
So this is peaking in the same thing.
So the format is the same where we're taking in the arguments, giving it, assigning it a value of
X to declare it, and then we're simply taking that value back and returning it back by ten.
And we're going to pass that into test to do a quick refresh.
And we do get the same value.
So it works the same way.
So this is a great example of how you can start working with the Arrow format and become more familiar
with it.