Hello People!
In the last posts, we have discussed the JavaScript Functions. In this tutorial, we are going through the most useful and advanced feature that comes with the ES6 version of JavaScript. So without wasting time let's start the tutorial.
In the below snap you can see that we have created a function (a simple function) that takes two parameters. Assign that to a variable named add and then printing the value on the console.
To understand the ES6 Arrow function javascript let's convert the simple function to an arrow function.
To convert the simple function to an arrow function, first of all, remove the keyword function and assign the function to a variable. And the reason we have to do this assignment here is that normal functions already create a variable of the name sum but as we don't have the function keyword so we now need to create our own variable to store this function.
In the above snap you can see that we have removed the function keyword and assign the function to a variable named sum1 and after that, we need an arrow sign which is the combination of = equal and > greater sign.
If we have only 1 line of code we can make it simpler and easier by removing the brackets as well.
even we don't need the return statement because anything after the brackets is assumed as a return.
Assume we have a function with the nameisPositive that takes one parameter.
So take care and see you with a new post.