Arrow function
Arrow functions are a shorter way to write functions in JavaScript.
Syntax
Normal Function
function add(a, b) {
return a + b;
}
Arrow function
const add = (a, b) => {
return a + b;
};
Arrow Function in JavaScript
An Arrow Function is a shorter and cleaner way to write functions in JavaScript
.Writing compact functions
.Avoiding the function keyword
.Lexical binding of this (important difference from normal functions)
Syntax of Arrow function :
Traditional function:
function add(a, b) {
return a + b;
}
Arrow function
const add = (a, b) => {
return a + b;
};
one return function
const add = (a, b) => a + b;
sub.map
()=>{ => (()=log("hi"))
const sub=[ ]
sub.map(()=> console.log("hii"));
sub.map(()=>prompt())
[arrow function & call back function]
Happy coding...
Top comments (0)