Q:

javascript arrow function

//If body has single statement
let myFunction = (arg1, arg2, ...argN) => expression

//for multiple statement
let myFunction = (arg1, arg2, ...argN) => {
    statement(s)
}
//example
let hello = (arg1,arg2) => "Hello " + arg1 + " Welcome To "+ arg2;
console.log(hello("User","Grepper"))
//Start checking js code on chrome inspect option
15
const suma = (num1, num2) => num1+num2
console.log(suma(2,3));
//5
2
// Non Arrow (standard way)
let add = function(x,y) {
  return x + y;
}
console.log(add(10,20)); // 30

// Arrow style
let add = (x,y) => x + y;
console.log(add(10,20)); // 30;

// You can still encapsulate
let add = (x, y) => { return x + y; };
3

/*this is an arrow function 
you can call it like an reqular function
and allow you to write shorter function syntaxes*/

hello = () => {
  return "Hello World!";
}

//for function that returns one static value you can do this

hello = () => "Hello World!";
2
hello = () => {
	return "Hi All";
}
0
let errow = () => {
  //the code you want to return;
};
Or
let errow = ('paramiter') => {
//the code you want to return
}
1
// an arrow function is also called a lambda or an anonymous function

let myFunction = () => {
  // some logic
}
0
const greet = (who) => {
  return `Hello, ${who}!`;
};

greet('Eric Cartman'); // => 'Hello, Eric Cartman!'
0
hello = () => {
  return "Hello World!";
}
0
const welcome = () => {
	console.log("THIS IS A ARROW FUNCTION")
}
0

New to Communities?

Join the community