Hey Guys, in this blog we are going to learn
about What is Java Script Arrow Functions and how we can use it.
Let's get started...
- Arrow function has been introduced in the ES
6.
- Arrow function allow us to write function
shortly and simply.
Arrow function looks like below
const funcName = (arg1, arg2, arg3, ..., argN)
=> expression
- Basically above expression means is it creates a function with name:
funcName with the arg1, arg2, ar3,...,argN and after
that, it's evaluate the expression and return the
results.
- Let's take a simple example let's print the sum of two number using arrow
function.
In this example as you can see here function name is sums and
it's take two arguments x and y and it's evaluate expression
( x+ y ) and based on evaluation it will return result so here it will
return result 25.
- Suppose if in any example if we have only one parameter so
in that case we can omitted parentheses from parameters
like below example.
- Suppose if you don't have any parameters then we can't
remove parentheses. It should be empty like below.
- Suppose if you want to perform some operation within the function then we can
also create multi-line arrow function like below.
If you guys have any query then you can drop a mail
to us on this mail id:
techoswag@gmail.com
Comments
Post a Comment