Arrow functions
Arrow functions are a more concise syntax for writing function expressions. They utilize a new token,
=>
, that looks like a fat arrow.Arrow functions make our code more concise, and simplify function scoping and the this keyword. They are one-line mini functions which work much like Lambdas in other languages like C# or Python.
Simple Example:
//simple function
const sayHello = function(name) {
return "hey" +name+ "!"
}
console.log(sayHello('Pritpal'));
Arrow function with filter():
//Arrow function
const sayHello = (name)=> `hey${ name} !`
console.log(sayHello('Pritpal'));
const todos=[{
title:'Buy bread',
isDone:true,
},{
title:'Go to Gym',
isDone:true,
},{
title:'learn java Script',
isDone:false,
}]
//filter() get the only value which are true or correct
const thingDone = todos.filter((todo) => todo.isDone === true)
console.log(thingDone);
0 Comments